Seite 187 von 340 ErsteErste ... 87 137 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 237 287 ... LetzteLetzte
Zeige Ergebnis 5.581 bis 5.610 von 10174

C/C++ Programming Help Thread

This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; i use a trace function that i created myself for debugging really helps here: Code: void trace(char text[100]){ FILE *pfile; ...

  
  1. #5581
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    i use a trace function that i created myself for debugging really helps here:

    Code:
    void trace(char text[100]){
    FILE *pfile;
    pfile = fopen("trace.txt","a+");
    fputs(text,pfile);
    fclose(pfile);
    }
    it's really great for debugging however i never got around to placeing in formating and such


    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  2. #5582
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    Has anyone already have succes with loading eboots from the xmb under 3.51 M33 , the se technique seems to fail :s

  3. #5583
    QJ Gamer Silver
    Points: 14.087, Level: 77
    Level completed: 10%, Points required for next Level: 363
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Ort
    Germany
    Beiträge
    926
    Points
    14.087
    Level
    77
    Downloads
    0
    Uploads
    0

    Standard

    Code:
    void trace(char text[100]){
    Why restricting yourself artificially to 100 chars?
    Raphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
    Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
    Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
    Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.

  4. #5584
    QJ Gamer Bronze
    Points: 5.402, Level: 47
    Level completed: 26%, Points required for next Level: 148
    Overall activity: 0%

    Registriert seit
    Apr 2007
    Beiträge
    468
    Points
    5.402
    Level
    47
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Moca
    I just need to say it -_-
    Its: char *hello="hello\0"; instead of char *hello="hello/0";
    Well, that would take up 7 bytes since theres 2 null characters now but the idea would be the same :|
    Simple error. Nothing big.
    crap, i missed that typo. but about the null terminator \0 thats stored as 1 byte, 0, or am i missing something?

  5. #5585
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von brethren
    crap, i missed that typo. but about the null terminator \0 thats stored as 1 byte, 0, or am i missing something?
    Yes, it is one byte in size. "String" takes 7 bytes of memory. "String\0" also takes 7 bytes of memory. However, strlen doesn't count '\0' as it is a NULL terminator so both strings would be 6 characters in length.

  6. #5586
    MiG
    MiG ist offline
    QJ Gamer Blue
    Points: 5.848, Level: 49
    Level completed: 49%, Points required for next Level: 102
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    499
    Points
    5.848
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Raphael
    Code:
    void trace(char text[100]){
    Why restricting yourself artificially to 100 chars?
    exactly..

    void trace(char text[])

    would be better.

  7. #5587
    QJ Gamer Gold
    Points: 17.453, Level: 84
    Level completed: 21%, Points required for next Level: 397
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    everywhere
    Beiträge
    3.526
    Points
    17.453
    Level
    84
    Downloads
    1
    Uploads
    0

    Standard

    because i don't have anything that well go over 100 besides i quickly made that function and didn't overly think about it
    1. Failed....again...
    2. http://slicer.gibbocool.com/ stay updated on all my projects
    3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been

  8. #5588
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    ok i have a memory adress (for example 0×88000000) and i want to storage the value 3 there , how do i do that?

  9. #5589
    It's good to be free...
    Points: 10.420, Level: 67
    Level completed: 93%, Points required for next Level: 30
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    2.440
    Points
    10.420
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Um, use the dereference operation?
    Code:
    int *pointer = new int;
    *int = 3;
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  10. #5590
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Code:
    int * pInt = (int*)(0×88000000);
    *pInt = 3;

  11. #5591
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Just 2 quick questions...

    1) Using graphics.c is it possible to store an image in the program to blit to screen, or does it have to be a .png file seperate?

    2) Can I return an array from a .prx, the array would be 1296 charactors long if this makes any difference.

    Thanks.
    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  12. #5592
    QJ Gamer Silver
    Points: 7.385, Level: 57
    Level completed: 18%, Points required for next Level: 165
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Finland
    Beiträge
    752
    Points
    7.385
    Level
    57
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    Just 2 quick questions...

    1) Using graphics.c is it possible to store an image in the program to blit to screen, or does it have to be a .png file seperate?

    2) Can I return an array from a .prx, the array would be 1296 charactors long if this makes any difference.

    Thanks.
    -Aura
    1) IIRC some version of graphics.c does have a function to load an image from buffer. Then you just bin2c the file and add it as an object to your makefile. The buffer will be unsigned char filename_start[]. Then declare the file in your main.c as extern unsigned char filename_start[].

    2) Return an address, then use it as a pointer.
    wheeee =:D

  13. #5593
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von MaTiAz
    IIRC some version of graphics.c does have a function to load an image from buffer. Then you just bin2c the file and add it as an object to your makefile. The buffer will be unsigned char filename_start[]. Then declare the file in your main.c as extern unsigned char filename_start[].
    Hi, I've taken a look for this, but I can't find it, just wondering if you could post a link or something, as I have to go now and can't search anymore.

    Cheers.
    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  14. #5594
    QJ Gamer Silver
    Points: 7.385, Level: 57
    Level completed: 18%, Points required for next Level: 165
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Finland
    Beiträge
    752
    Points
    7.385
    Level
    57
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    Hi, I've taken a look for this, but I can't find it, just wondering if you could post a link or something, as I have to go now and can't search anymore.

    Cheers.
    -Aura
    Yeah, I'll just copypaste my graphics.c/.h and required stuff. They were ripped from some version of LuaPlayer (don't remember which one though).
    Spoiler for graphics.c:
    Code:
    #include <stdlib.h>
    #include <malloc.h>
    #include <pspdisplay.h>
    #include <psputils.h>
    #include <png.h>
    #include <pspgu.h>
    
    #include <jpeglib.h>
    #include <jerror.h>
    
    #include "graphics.h"
    #include "framebuffer.h"
    
    #define IS_ALPHA(color) (((color)&0xff000000)==0xff000000?0:1)
    #define FRAMEBUFFER_SIZE (PSP_LINE_SIZE*SCREEN_HEIGHT*4)
    #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
    
    typedef struct
    {
    	unsigned short u, v;
    	short x, y, z;
    } Vertex;
    
    extern u8 msx[];
    
    unsigned int __attribute__((aligned(16))) list[262144];
    static int dispBufferNumber;
    static int initialized = 0;
    
    static int getNextPower2(int width)
    {
    	int b = width;
    	int n;
    	for (n = 0; b != 0; n++) b >>= 1;
    	b = 1 << n;
    	if (b == 2 * width) b >>= 1;
    	return b;
    }
    
    Color* getVramDrawBuffer()
    {
    	Color* vram = (Color*) g_vram_base;
    	if (dispBufferNumber == 0) vram += FRAMEBUFFER_SIZE / sizeof(Color);
    	return vram;
    }
    
    Color* getVramDisplayBuffer()
    {
    	Color* vram = (Color*) g_vram_base;
    	if (dispBufferNumber == 1) vram += FRAMEBUFFER_SIZE / sizeof(Color);
    	return vram;
    }
    
    void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
    {
    }
    
    static int isJpegFile(const char* filename)
    {
    	char* suffix = strrchr(filename, '.');
    	if (suffix) {
    		if (stricmp(suffix, ".jpg") == 0 || stricmp(suffix, ".jpeg") == 0) return 1;
    	}
    	return 0;
    }
    
    Image* loadImage(const char* filename)
    {
    	if (isJpegFile(filename)) {
    		return loadJpegImage(filename);
    	} else {
    		return loadPngImage(filename);
    	}
    }
    
    Image* loadPngImageImpl(png_structp png_ptr)
    {
    	unsigned int sig_read = 0;
    	png_uint_32 width, height, x, y;
    	int bit_depth, color_type, interlace_type;
    	u32* line;
    	png_infop info_ptr;
    	info_ptr = png_create_info_struct(png_ptr);
    	if (info_ptr == NULL) {
    		png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
    		return NULL;
    	}
    	png_set_sig_bytes(png_ptr, sig_read);
    	png_read_info(png_ptr, info_ptr);
    	png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, int_p_NULL, int_p_NULL);
    	if (width > 512 || height > 512) {
    		png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
    		return NULL;
    	}
    	Image* image = (Image*) malloc(sizeof(Image));
    	image->imageWidth = width;
    	image->imageHeight = height;
    	image->textureWidth = getNextPower2(width);
    	image->textureHeight = getNextPower2(height);
    	png_set_strip_16(png_ptr);
    	png_set_packing(png_ptr);
    	if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png_ptr);
    	if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_gray_1_2_4_to_8(png_ptr);
    	if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
    	png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
    	image->data = (Color*) memalign(16, image->textureWidth * image->textureHeight * sizeof(Color));
    	if (!image->data) {
    		free(image);
    		png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
    		return NULL;
    	}
    	line = (u32*) malloc(width * 4);
    	if (!line) {
    		free(image->data);
    		free(image);
    		png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
    		return NULL;
    	}
    	for (y = 0; y < height; y++) {
    		png_read_row(png_ptr, (u8*) line, png_bytep_NULL);
    		for (x = 0; x < width; x++) {
    			u32 color = line[x];
    			image->data[x + y * image->textureWidth] =  color;
    		}
    	}
    	free(line);
    	png_read_end(png_ptr, info_ptr);
    	png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
    	return image;
    }
    
    Image* loadPngImage(const char* filename)
    {
    	png_structp png_ptr;
    	FILE *fp;
    
    	if ((fp = fopen(filename, "rb")) == NULL) return NULL;
    	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    	if (png_ptr == NULL) {
    		fclose(fp);
    		return NULL;;
    	}
    	png_init_io(png_ptr, fp);
    	Image* image = loadPngImageImpl(png_ptr);
    	fclose(fp);
    	return image;
    }
    
    Image* loadJpegImageImpl(struct jpeg_decompress_struct dinfo)
    {
    	jpeg_read_header(&dinfo, 1);
    	int width = dinfo.image_width;
    	int height = dinfo.image_height;
    	jpeg_start_decompress(&dinfo);
    	Image* image = (Image*) malloc(sizeof(Image));
    	if (!image) {
    		jpeg_destroy_decompress(&dinfo);
    		return NULL;
    	}
    	if (width > 512 || height > 512) {
    		jpeg_destroy_decompress(&dinfo);
    		return NULL;
    	}
    	image->imageWidth = width;
    	image->imageHeight = height;
    	image->textureWidth = getNextPower2(width);
    	image->textureHeight = getNextPower2(height);
    	image->data = (Color*) memalign(16, image->textureWidth * image->textureHeight * sizeof(Color));
    	u8* line = (u8*) malloc(width * 3);
    	if (!line) {
    		jpeg_destroy_decompress(&dinfo);
    		return NULL;
    	}
    	if (dinfo.jpeg_color_space == JCS_GRAYSCALE) {
    		while (dinfo.output_scanline < dinfo.output_height) {
    			int y = dinfo.output_scanline;
    			jpeg_read_scanlines(&dinfo, &line, 1);
    			int x;
    			for (x = 0; x < width; x++) {
    				Color c = line[x];
    				image->data[x + image->textureWidth * y] = c | (c << 8) | (c << 16) | 0xff000000;;
    			}
    		}
    	} else {
    		while (dinfo.output_scanline < dinfo.output_height) {
    			int y = dinfo.output_scanline;
    			jpeg_read_scanlines(&dinfo, &line, 1);
    			u8* linePointer = line;
    			int x;
    			for (x = 0; x < width; x++) {
    				Color c = *(linePointer++);
    				c |= (*(linePointer++)) << 8;
    				c |= (*(linePointer++)) << 16;
    				image->data[x + image->textureWidth * y] = c | 0xff000000;
    			}
    		}
    	}
    	jpeg_finish_decompress(&dinfo);
    	jpeg_destroy_decompress(&dinfo);
    	free(line);
    	return image;
    }
    
    Image* loadJpegImage(const char* filename)
    {
    	struct jpeg_decompress_struct dinfo;
    	struct jpeg_error_mgr jerr;
    	dinfo.err = jpeg_std_error(&jerr);
    	jpeg_create_decompress(&dinfo);
    	FILE* inFile = fopen(filename, "rb");
    	if (!inFile) {
    		jpeg_destroy_decompress(&dinfo);
    		return NULL;
    	}
    	jpeg_stdio_src(&dinfo, inFile);
    	Image* image = loadJpegImageImpl(dinfo);
    	fclose(inFile);
    	return image;
    }
    
    
    // code for jpeg memory source
    typedef struct {
    	struct jpeg_source_mgr pub;	/* public fields */
    
    	const unsigned char* membuff;	/* The input buffer */
    	int location;			/* Current location in buffer */ 
    	int membufflength;            /* The length of the input buffer */
    	JOCTET * buffer;		/* start of buffer */
    	boolean start_of_buff;	/* have we gotten any data yet? */
    } mem_source_mgr;
    
    typedef mem_source_mgr* mem_src_ptr;
    
    #define INPUT_BUF_SIZE  4096	/* choose an efficiently fread'able size */
    
    
    METHODDEF(void) mem_init_source (j_decompress_ptr cinfo) {
    	mem_src_ptr src;
    
    	src = (mem_src_ptr) cinfo->src;
    
    	/* We reset the empty-input-file flag for each image,
    	* but we don't clear the input buffer.
    	* This is correct behavior for reading a series of images from one source.
    	*/
    	src->location = 0;
    	src->start_of_buff = 1;
    }
    
    
    METHODDEF(boolean) mem_fill_input_buffer (j_decompress_ptr cinfo) {
    	mem_src_ptr src;
    	size_t bytes_to_read;
    	size_t nbytes;
    
    	src = (mem_src_ptr) cinfo->src;
    
    	if((src->location)+INPUT_BUF_SIZE >= src->membufflength)
    		bytes_to_read = src->membufflength - src->location;
    	else
    		bytes_to_read = INPUT_BUF_SIZE;
    
    	memcpy(src->buffer, (src->membuff)+(src->location), bytes_to_read);
    	nbytes = bytes_to_read;
    	src->location += (int) bytes_to_read;
    
    	if (nbytes <= 0) {
    		if (src->start_of_buff)	/* Treat empty input file as fatal error */
    			ERREXIT(cinfo, JERR_INPUT_EMPTY);
    		WARNMS(cinfo, JWRN_JPEG_EOF);
    		/* Insert a fake EOI marker */
    		src->buffer[0] = (JOCTET) 0xFF;
    		src->buffer[1] = (JOCTET) JPEG_EOI;
    		nbytes = 2;
    	}
    
    	src->pub.next_input_byte = src->buffer;
    	src->pub.bytes_in_buffer = nbytes;
    	src->start_of_buff = 0;
    
    	return 1;
    }
    
    
    METHODDEF(void) mem_skip_input_data (j_decompress_ptr cinfo, long num_bytes) {
    	mem_src_ptr src;
    
    	src = (mem_src_ptr) cinfo->src;
    
    	if (num_bytes > 0) {
    		while (num_bytes > (long) src->pub.bytes_in_buffer) {
    			num_bytes -= (long) src->pub.bytes_in_buffer;
    			mem_fill_input_buffer(cinfo);
    		}
    		src->pub.next_input_byte += (size_t) num_bytes;
    		src->pub.bytes_in_buffer -= (size_t) num_bytes;
    	}
    }
    
    
    METHODDEF(void) mem_term_source (j_decompress_ptr cinfo) {
    }
    
    
    GLOBAL(void) jpeg_mem_src (j_decompress_ptr cinfo, const unsigned char *mbuff, int mbufflen) {
    	mem_src_ptr src;
    
    	if (cinfo->src == NULL) {	/* first time for this JPEG object? */
    		cinfo->src = (struct jpeg_source_mgr *)
    			(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
    			sizeof(mem_source_mgr));
    		src = (mem_src_ptr) cinfo->src;
    		src->buffer = (JOCTET *)
    			(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
    			INPUT_BUF_SIZE * sizeof(JOCTET));
    	}
    
    	src = (mem_src_ptr) cinfo->src;
    	src->pub.init_source = mem_init_source;
    	src->pub.fill_input_buffer = mem_fill_input_buffer;
    	src->pub.skip_input_data = mem_skip_input_data;
    	src->pub.resync_to_restart = jpeg_resync_to_restart;
    	src->pub.term_source = mem_term_source;
    	src->membuff = mbuff;
    	src->membufflength = mbufflen;
    	src->pub.bytes_in_buffer = 0;    /* forces fill_input_buffer on first read */
    	src->pub.next_input_byte = NULL; /* until buffer loaded */
    }
    
    typedef struct {
    	const unsigned char *data;
    	png_size_t size;
    	png_size_t seek;
    } PngData;
    	
    static void ReadPngData(png_structp png_ptr, png_bytep data, png_size_t length)
    {
    	PngData *pngData = (PngData*) png_get_io_ptr(png_ptr);
    	if (pngData) {
                    png_size_t i;
    		for (i = 0; i < length; i++) {
    			if (pngData->seek >= pngData->size) break;
    			data[i] = pngData->data[pngData->seek++];
    		}
    	}
    }
    
    Image* loadImageFromMemory(const unsigned char* data, int len)
    {
    	if (len < 8) return NULL;
    	
    	// test for PNG
    	if (data[0] == 137 && data[1] == 80 && data[2] == 78 && data[3] == 71
    		&& data[4] == 13 && data[5] == 10 && data[6] == 26 && data[7] ==10)
    	{
    		png_structp png_ptr;
    		png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    		if (png_ptr == NULL) {
    			return NULL;;
    		}
    		PngData pngData;
    		pngData.data = data;
    		pngData.size = len;
    		pngData.seek = 0;
    		png_set_read_fn(png_ptr, (void *) &pngData, ReadPngData);
    		Image* image = loadPngImageImpl(png_ptr);
    		return image;
    	} else {
    		// assume JPG
    		struct jpeg_decompress_struct dinfo;
    		struct jpeg_error_mgr jerr;
    		dinfo.err = jpeg_std_error(&jerr);
    		jpeg_create_decompress(&dinfo);
    		jpeg_mem_src(&dinfo, data, len);
    		Image* image = loadJpegImageImpl(dinfo);
    		return image;
    	}
    }
    
    void blitImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination)
    {
    	Color* destinationData = &destination->data[destination->textureWidth * dy + dx];
    	int destinationSkipX = destination->textureWidth - width;
    	Color* sourceData = &source->data[source->textureWidth * sy + sx];
    	int sourceSkipX = source->textureWidth - width;
    	int x, y;
    	for (y = 0; y < height; y++, destinationData += destinationSkipX, sourceData += sourceSkipX) {
    		for (x = 0; x < width; x++, destinationData++, sourceData++) {
    			*destinationData = *sourceData;
    		}
    	}
    }
    
    void blitImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy)
    {
    	if (!initialized) return;
    	Color* vram = getVramDrawBuffer();
    	sceKernelDcacheWritebackInvalidateAll();
    	guStart();
    	sceGuCopyImage(GU_PSM_8888, sx, sy, width, height, source->textureWidth, source->data, dx, dy, PSP_LINE_SIZE, vram);
    	sceGuFinish();
    	sceGuSync(0,0);
    }
    
    void blitAlphaImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination)
    {
    	Color* destinationData = &destination->data[destination->textureWidth * dy + dx];
    	int destinationSkipX = destination->textureWidth - width;
    	Color* sourceData = &source->data[source->textureWidth * sy + sx];
    	int sourceSkipX = source->textureWidth - width;
    	int x, y;
    	s32 rcolorc, gcolorc, bcolorc, acolorc,rcolord, gcolord, bcolord, acolord;
    	for (y = 0; y < height; y++, destinationData += destinationSkipX, sourceData += sourceSkipX) {
    		for (x = 0; x < width; x++, destinationData++, sourceData++) {
    			Color color = *sourceData;
    			if (!IS_ALPHA(color)) {
    				*destinationData = color;
    			} else {
    				rcolorc = color & 0xff;
    				gcolorc = (color >> 8) & 0xff;
    				bcolorc = (color >> 16) & 0xff;
    				acolorc = (color >> 24) & 0xff;
    				rcolord = *destinationData & 0xff;
    				gcolord = (*destinationData >> 8) & 0xff;
    				bcolord = (*destinationData >> 16) & 0xff;
    				acolord = (*destinationData >> 24) & 0xff;
    				
    				rcolorc = ((acolorc*rcolorc)>>8) + (((255-acolorc) * rcolord)>>8);
    				if (rcolorc > 255) rcolorc = 255;
    				gcolorc = ((acolorc*gcolorc)>>8) + (((255-acolorc) * gcolord)>>8);
    				if (gcolorc > 255) gcolorc = 255;
    				bcolorc = ((acolorc*bcolorc)>>8) + (((255-acolorc) * bcolord)>>8);
    				if (bcolorc > 255) bcolorc = 255;
    				if (acolord + acolorc < 255) {
    					acolorc = acolord+acolorc;
    				} else {
    					acolorc = 255;
    				}
    				*destinationData = rcolorc | (gcolorc << 8) | (bcolorc << 16) | (acolorc << 24);
    			}
    		}
    	}
    }
    
    void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy)
    {
    	if (!initialized) return;
    
    	sceKernelDcacheWritebackInvalidateAll();
    	guStart();
    	sceGuTexImage(0, source->textureWidth, source->textureHeight, source->textureWidth, (void*) source->data);
    	float u = 1.0f / ((float)source->textureWidth);
    	float v = 1.0f / ((float)source->textureHeight);
    	sceGuTexScale(u, v);
    	
    	int j = 0;
    	while (j < width) {
    		Vertex* vertices = (Vertex*) sceGuGetMemory(2 * sizeof(Vertex));
    		int sliceWidth = 64;
    		if (j + sliceWidth > width) sliceWidth = width - j;
    		vertices[0].u = sx + j;
    		vertices[0].v = sy;
    		vertices[0].x = dx + j;
    		vertices[0].y = dy;
    		vertices[0].z = 0;
    		vertices[1].u = sx + j + sliceWidth;
    		vertices[1].v = sy + height;
    		vertices[1].x = dx + j + sliceWidth;
    		vertices[1].y = dy + height;
    		vertices[1].z = 0;
    		sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);
    		j += sliceWidth;
    	}
    	
    	sceGuFinish();
    	sceGuSync(0, 0);
    }
    
    Image* createImage(int width, int height)
    {
    	Image* image = (Image*) malloc(sizeof(Image));
    	if (!image) return NULL;
    	image->imageWidth = width;
    	image->imageHeight = height;
    	image->textureWidth = getNextPower2(width);
    	image->textureHeight = getNextPower2(height);
    	image->data = (Color*) memalign(16, image->textureWidth * image->textureHeight * sizeof(Color));
    	if (!image->data) return NULL;
    	memset(image->data, 0, image->textureWidth * image->textureHeight * sizeof(Color));
    	return image;
    }
    
    void freeImage(Image* image)
    {
    	free(image->data);
    	free(image);
    }
    
    void clearImage(Color color, Image* image)
    {
    	int i;
    	int size = image->textureWidth * image->textureHeight;
    	Color* data = image->data;
    	for (i = 0; i < size; i++, data++) *data = color;
    }
    
    void clearScreen(Color color)
    {
    	if (!initialized) return;
    	guStart();
    	sceGuClearColor(color);
    	sceGuClearDepth(0);
    	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
    	sceGuFinish();
    	sceGuSync(0, 0);
    }
    
    void fillImageRect(Color color, int x0, int y0, int width, int height, Image* image)
    {
    	int skipX = image->textureWidth - width;
    	int x, y;
    	Color* data = image->data + x0 + y0 * image->textureWidth;
    	for (y = 0; y < height; y++, data += skipX) {
    		for (x = 0; x < width; x++, data++) *data = color;
    	}
    }
    
    void fillScreenRect(Color color, int x0, int y0, int width, int height)
    {
    	if (!initialized) return;
    	int skipX = PSP_LINE_SIZE - width;
    	int x, y;
    	Color* data = getVramDrawBuffer() + x0 + y0 * PSP_LINE_SIZE;
    	for (y = 0; y < height; y++, data += skipX) {
    		for (x = 0; x < width; x++, data++) *data = color;
    	}
    }
    
    void putPixelScreen(Color color, int x, int y)
    {
    	Color* vram = getVramDrawBuffer();
    	vram[PSP_LINE_SIZE * y + x] = color;
    }
    
    void putPixelImage(Color color, int x, int y, Image* image)
    {
    	image->data[x + y * image->textureWidth] = color;
    }
    
    Color getPixelScreen(int x, int y)
    {
    	Color* vram = getVramDrawBuffer();
    	return vram[PSP_LINE_SIZE * y + x];
    }
    
    Color getPixelImage(int x, int y, Image* image)
    {
    	return image->data[x + y * image->textureWidth];
    }
    
    void printTextScreen(int x, int y, const char* text, u32 color)
    {
    	int i, j, l;
    	u8 *font;
    	Color *vram_ptr;
    	Color *vram;
    	
    	if (!initialized) return;
            size_t c;
    	for (c = 0; c < strlen(text); c++) {
    		if (x < 0 || x + 8 > SCREEN_WIDTH || y < 0 || y + 8 > SCREEN_HEIGHT) break;
    		char ch = text[c];
    		vram = getVramDrawBuffer() + x + y * PSP_LINE_SIZE;
    		
    		font = &msx[ (int)ch * 8];
    		for (i = l = 0; i < 8; i++, l += 8, font++) {
    			vram_ptr  = vram;
    			for (j = 0; j < 8; j++) {
    				if ((*font & (128 >> j))) *vram_ptr = color;
    				vram_ptr++;
    			}
    			vram += PSP_LINE_SIZE;
    		}
    		x += 8;
    	}
    }
    
    void printTextImage(int x, int y, const char* text, u32 color, Image* image)
    {
    	int i, j, l;
    	u8 *font;
    	Color *data_ptr;
    	Color *data;
    	
    	if (!initialized) return;
            size_t c;
    	for (c = 0; c < strlen(text); c++) {
    		if (x < 0 || x + 8 > image->imageWidth || y < 0 || y + 8 > image->imageHeight) break;
    		char ch = text[c];
    		data = image->data + x + y * image->textureWidth;
    		
    		font = &msx[ (int)ch * 8];
    		for (i = l = 0; i < 8; i++, l += 8, font++) {
    			data_ptr  = data;
    			for (j = 0; j < 8; j++) {
    				if ((*font & (128 >> j))) *data_ptr = color;
    				data_ptr++;
    			}
    			data += image->textureWidth;
    		}
    		x += 8;
    	}
    }
    
    static void fontPrintTextImpl(FT_Bitmap* bitmap, int xofs, int yofs, Color color, Color* framebuffer, int width, int height, int lineSize)
    {
    	u8 rf = color & 0xff; 
    	u8 gf = (color >> 8) & 0xff;
    	u8 bf = (color >> 16) & 0xff;
    	u8 af = (color >> 24) & 0xff;
    	
    	u8* line = bitmap->buffer;
    	Color* fbLine = framebuffer + xofs + yofs * lineSize;
    	int y;
    	for (y = 0; y < bitmap->rows; y++) {
    		u8* column = line;
    		Color* fbColumn = fbLine;
    		int x;
                    for (x = 0; x < bitmap->width; x++) {
    			if (x + xofs < width && x + xofs >= 0 && y + yofs < height && y + yofs >= 0) {
    				u8 val = *column;
    				color = *fbColumn;
    				u8 r = color & 0xff; 
    				u8 g = (color >> 8) & 0xff;
    				u8 b = (color >> 16) & 0xff;
    				u8 a = (color >> 24) & 0xff;
    				r = rf * val / 255 + (255 - val) * r / 255;
    				g = gf * val / 255 + (255 - val) * g / 255;
    				b = bf * val / 255 + (255 - val) * b / 255;
    				a = af * val / 255 + (255 - val) * a / 255;
    				*fbColumn = r | (g << 8) | (b << 16) | (a << 24);
    			}
    			column++;
    			fbColumn++;
    		}
    		line += bitmap->pitch;
    		fbLine += lineSize;
    	}
    }
    
    void fontPrintTextImage(FT_Bitmap* bitmap, int x, int y, Color color, Image* image)
    {
    	fontPrintTextImpl(bitmap, x, y, color, image->data, image->imageWidth, image->imageHeight, image->textureWidth);
    }
    
    void fontPrintTextScreen(FT_Bitmap* bitmap, int x, int y, Color color)
    {
    	fontPrintTextImpl(bitmap, x, y, color, getVramDrawBuffer(), SCREEN_WIDTH, SCREEN_HEIGHT, PSP_LINE_SIZE);
    }
    
    void saveImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha)
    {
    	if (isJpegFile(filename)) {
    		saveJpegImage(filename, data, width, height, lineSize);
    	} else {
    		savePngImage(filename, data, width, height, lineSize, saveAlpha);
    	}
    }
    
    void savePngImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha)
    {
    	png_structp png_ptr;
    	png_infop info_ptr;
    	FILE* fp;
    	int i, x, y;
    	u8* line;
    	
    	if ((fp = fopen(filename, "wb")) == NULL) return;
    	png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    	if (!png_ptr) return;
    	info_ptr = png_create_info_struct(png_ptr);
    	if (!info_ptr) {
    		png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
    		return;
    	}
    	png_init_io(png_ptr, fp);
    	png_set_IHDR(png_ptr, info_ptr, width, height, 8,
    		saveAlpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB,
    		PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
    	png_write_info(png_ptr, info_ptr);
    	line = (u8*) malloc(width * (saveAlpha ? 4 : 3));
    	for (y = 0; y < height; y++) {
    		for (i = 0, x = 0; x < width; x++) {
    			Color color = data[x + y * lineSize];
    			u8 r = color & 0xff; 
    			u8 g = (color >> 8) & 0xff;
    			u8 b = (color >> 16) & 0xff;
    			u8 a = saveAlpha ? (color >> 24) & 0xff : 0xff;
    			line[i++] = r;
    			line[i++] = g;
    			line[i++] = b;
    			if (saveAlpha) line[i++] = a;
    		}
    		png_write_row(png_ptr, line);
    	}
    	free(line);
    	png_write_end(png_ptr, info_ptr);
    	png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
    	fclose(fp);
    }
    
    void saveJpegImage(const char* filename, Color* data, int width, int height, int lineSize)
    {
    	FILE* outFile = fopen(filename, "wb");
    	if (!outFile) return;
    	struct jpeg_error_mgr jerr;
    	struct jpeg_compress_struct cinfo;
    	cinfo.err = jpeg_std_error(&jerr);
    	jpeg_create_compress(&cinfo);
    	jpeg_stdio_dest(&cinfo, outFile);
    	cinfo.image_width = width;
    	cinfo.image_height = height;
    	cinfo.input_components = 3;
    	cinfo.in_color_space = JCS_RGB;
    	jpeg_set_defaults(&cinfo);
    	jpeg_set_quality(&cinfo, 100, 1);
    	jpeg_start_compress(&cinfo, 1);
    	u8* row = (u8*) malloc(width * 3);
    	if (!row) return;
    	int y;
    	for (y = 0; y < height; y++) {
    		u8* rowPointer = row;
    		int x;
                    for (x = 0; x < width; x++) {
    			Color c = data[x + cinfo.next_scanline * lineSize];
    			*(rowPointer++) = c & 0xff;
    			*(rowPointer++) = (c >> 8) & 0xff;
    			*(rowPointer++) = (c >> 16) & 0xff;
    		}
    		jpeg_write_scanlines(&cinfo, &row, 1);
    	}
    	jpeg_finish_compress(&cinfo);
    	jpeg_destroy_compress(&cinfo);
    	fclose(outFile);
    	free(row);
    }
    
    void flipScreen()
    {
    	if (!initialized) return;
    	sceGuSwapBuffers();
    	dispBufferNumber ^= 1;
    }
    
    static void drawLine(int x0, int y0, int x1, int y1, int color, Color* destination, int width)
    {
    	int dy = y1 - y0;
    	int dx = x1 - x0;
    	int stepx, stepy;
    	
    	if (dy < 0) { dy = -dy;  stepy = -width; } else { stepy = width; }
    	if (dx < 0) { dx = -dx;  stepx = -1; } else { stepx = 1; }
    	dy <<= 1;
    	dx <<= 1;
    	
    	y0 *= width;
    	y1 *= width;
    	destination[x0+y0] = color;
    	if (dx > dy) {
    		int fraction = dy - (dx >> 1);
    		while (x0 != x1) {
    			if (fraction >= 0) {
    				y0 += stepy;
    				fraction -= dx;
    			}
    			x0 += stepx;
    			fraction += dy;
    			destination[x0+y0] = color;
    		}
    	} else {
    		int fraction = dx - (dy >> 1);
    		while (y0 != y1) {
    			if (fraction >= 0) {
    				x0 += stepx;
    				fraction -= dy;
    			}
    			y0 += stepy;
    			fraction += dx;
    			destination[x0+y0] = color;
    		}
    	}
    }
    
    void drawLineScreen(int x0, int y0, int x1, int y1, Color color)
    {
    	drawLine(x0, y0, x1, y1, color, getVramDrawBuffer(), PSP_LINE_SIZE);
    }
    
    void drawLineImage(int x0, int y0, int x1, int y1, Color color, Image* image)
    {
    	drawLine(x0, y0, x1, y1, color, image->data, image->textureWidth);
    }
    
    #define BUF_WIDTH (512)
    #define SCR_WIDTH (480)
    #define SCR_HEIGHT (272)
    #define PIXEL_SIZE (4) /* change this if you change to another screenmode */
    #define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
    #define ZBUF_SIZE (BUF_WIDTH SCR_HEIGHT * 2) /* zbuffer seems to be 16-bit? */
    
    void initGraphics()
    {
    	dispBufferNumber = 0;
    
    	sceGuInit();
    
    	guStart();
    	sceGuDrawBuffer(GU_PSM_8888, (void*)FRAMEBUFFER_SIZE, PSP_LINE_SIZE);
    	sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, (void*)0, PSP_LINE_SIZE);
    	sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
    	sceGuDepthBuffer((void*) (FRAMEBUFFER_SIZE*2), PSP_LINE_SIZE);
    	sceGuOffset(2048 - (SCREEN_WIDTH / 2), 2048 - (SCREEN_HEIGHT / 2));
    	sceGuViewport(2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT);
    	sceGuDepthRange(0xc350, 0x2710);
    	sceGuScissor(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    	sceGuEnable(GU_SCISSOR_TEST);
    	sceGuAlphaFunc(GU_GREATER, 0, 0xff);
    	sceGuEnable(GU_ALPHA_TEST);
    	sceGuDepthFunc(GU_GEQUAL);
    	sceGuEnable(GU_DEPTH_TEST);
    	sceGuFrontFace(GU_CW);
    	sceGuShadeModel(GU_SMOOTH);
    	sceGuEnable(GU_CULL_FACE);
    	sceGuEnable(GU_TEXTURE_2D);
    	sceGuEnable(GU_CLIP_PLANES);
    	sceGuTexMode(GU_PSM_8888, 0, 0, 0);
    	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
    	sceGuTexFilter(GU_NEAREST, GU_NEAREST);
    	sceGuAmbientColor(0xffffffff);
    	sceGuEnable(GU_BLEND);
    	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
    	sceGuFinish();
    	sceGuSync(0, 0);
    
    	sceDisplayWaitVblankStart();
    	sceGuDisplay(GU_TRUE);
    	initialized = 1;
    }
    
    void disableGraphics()
    {
    	initialized = 0;
    }
    
    void guStart()
    {
    	sceGuStart(GU_DIRECT, list);
    }

    Spoiler for graphics.h:
    Code:
    #ifndef GRAPHICS_H
    #define GRAPHICS_H
    
    #include <ft2build.h>
    #include FT_FREETYPE_H
    
    #include <psptypes.h>
    
    #define	PSP_LINE_SIZE 512
    #define SCREEN_WIDTH 480
    #define SCREEN_HEIGHT 272
    
    typedef u32 Color;
    #define A(color) ((u8)(color >> 24 & 0xFF))
    #define B(color) ((u8)(color >> 16 & 0xFF))
    #define G(color) ((u8)(color >> 8 & 0xFF))
    #define R(color) ((u8)(color & 0xFF))
    
    typedef struct
    {
    	int textureWidth;  // the real width of data, 2^n with n>=0
    	int textureHeight;  // the real height of data, 2^n with n>=0
    	int imageWidth;  // the image width
    	int imageHeight;
    	Color* data;
    } Image;
    
    /**
     * Load a PNG or JPEG image (depends on the filename suffix).
     *
     * @pre filename != NULL
     * @param filename - filename of the PNG image to load
     * @return pointer to a new allocated Image struct, or NULL on failure
     */
    extern Image* loadImage(const char* filename);
    
    /**
     * Load a PNG image.
     *
     * @pre filename != NULL
     * @param filename - filename of the PNG image to load
     * @return pointer to a new allocated Image struct, or NULL on failure
     */
    extern Image* loadPngImage(const char* filename);
    
    /**
     * Load a JPEG image.
     *
     * @pre filename != NULL
     * @param filename - filename of the JPEG image to load
     * @return pointer to a new allocated Image struct, or NULL on failure
     */
    extern Image* loadJpegImage(const char* filename);
    
    /**
     * Load a PNG or JPEG image from in-memory data (with auto detection of the format).
     *
     * @pre data != NULL && len >0
     * @param data - the in-memory bytes of the image
     * @param len - the number of valid bytes at the data pointer
     * @return pointer to a new allocated Image struct, or NULL on failure
     */
    extern Image* loadImageFromMemory(const unsigned char* data, int len);
    
    /**
     * Blit a rectangle part of an image to another image.
     *
     * @pre source != NULL && destination != NULL &&
     *      sx >= 0 && sy >= 0 &&
     *      width > 0 && height > 0 &&
     *      sx + width <= source->width && sy + height <= source->height &&
     *      dx + width <= destination->width && dy + height <= destination->height
     * @param sx - left position of rectangle in source image
     * @param sy - top position of rectangle in source image
     * @param width - width of rectangle in source image
     * @param height - height of rectangle in source image
     * @param source - pointer to Image struct of the source image
     * @param dx - left target position in destination image
     * @param dy - top target position in destination image
     * @param destination - pointer to Image struct of the destination image
     */
    extern void blitImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination);
    
    /**
     * Blit a rectangle part of an image to screen.
     *
     * @pre source != NULL && destination != NULL &&
     *      sx >= 0 && sy >= 0 &&
     *      width > 0 && height > 0 &&
     *      sx + width <= source->width && sy + height <= source->height &&
     *      dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT
     * @param sx - left position of rectangle in source image
     * @param sy - top position of rectangle in source image
     * @param width - width of rectangle in source image
     * @param height - height of rectangle in source image
     * @param source - pointer to Image struct of the source image
     * @param dx - left target position in destination image
     * @param dy - top target position in destination image
     */
    extern void blitImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy);
    
    /**
     * Blit a rectangle part of an image to another image without alpha pixels in source image.
     *
     * @pre source != NULL && destination != NULL &&
     *      sx >= 0 && sy >= 0 &&
     *      width > 0 && height > 0 &&
     *      sx + width <= source->width && sy + height <= source->height &&
     *      dx + width <= destination->width && dy + height <= destination->height
     * @param sx - left position of rectangle in source image
     * @param sy - top position of rectangle in source image
     * @param width - width of rectangle in source image
     * @param height - height of rectangle in source image
     * @param source - pointer to Image struct of the source image
     * @param dx - left target position in destination image
     * @param dy - top target position in destination image
     * @param destination - pointer to Image struct of the destination image
     */
    extern void blitAlphaImageToImage(int sx, int sy, int width, int height, Image* source, int dx, int dy, Image* destination);
    
    /**
     * Blit a rectangle part of an image to screen without alpha pixels in source image.
     *
     * @pre source != NULL && destination != NULL &&
     *      sx >= 0 && sy >= 0 &&
     *      width > 0 && height > 0 &&
     *      sx + width <= source->width && sy + height <= source->height &&
     *      dx + width <= SCREEN_WIDTH && dy + height <= SCREEN_HEIGHT
     * @param sx - left position of rectangle in source image
     * @param sy - top position of rectangle in source image
     * @param width - width of rectangle in source image
     * @param height - height of rectangle in source image
     * @param source - pointer to Image struct of the source image
     * @param dx - left target position in destination image
     * @param dy - top target position in destination image
     */
    extern void blitAlphaImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy);
    
    /**
     * Create an empty image.
     *
     * @pre width > 0 && height > 0 && width <= 512 && height <= 512
     * @param width - width of the new image
     * @param height - height of the new image
     * @return pointer to a new allocated Image struct, all pixels initialized to color 0, or NULL on failure
     */
    extern Image* createImage(int width, int height);
    
    /**
     * Frees an allocated image.
     *
     * @pre image != null
     * @param image a pointer to an image struct
     */
    extern void freeImage(Image* image);
    
    /**
     * Initialize all pixels of an image with a color.
     *
     * @pre image != NULL
     * @param color - new color for the pixels
     * @param image - image to clear
     */
    extern void clearImage(Color color, Image* image);
    
    /**
     * Initialize all pixels of the screen with a color.
     *
     * @param color - new color for the pixels
     */
    extern void clearScreen(Color color);
    
    /**
     * Fill a rectangle of an image with a color.
     *
     * @pre image != NULL
     * @param color - new color for the pixels
     * @param x0 - left position of rectangle in image
     * @param y0 - top position of rectangle in image
     * @param width - width of rectangle in image
     * @param height - height of rectangle in image
     * @param image - image
     */
    extern void fillImageRect(Color color, int x0, int y0, int width, int height, Image* image);
    
    /**
     * Fill a rectangle of an image with a color.
     *
     * @pre image != NULL
     * @param color - new color for the pixels
     * @param x0 - left position of rectangle in image
     * @param y0 - top position of rectangle in image
     * @param width - width of rectangle in image
     * @param height - height of rectangle in image
     */
    extern void fillScreenRect(Color color, int x0, int y0, int width, int height);
    
    /**
     * Set a pixel on screen to the specified color.
     *
     * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT
     * @param color - new color for the pixels
     * @param x - left position of the pixel
     * @param y - top position of the pixel
     */
    extern void putPixelScreen(Color color, int x, int y);
    
    /**
     * Set a pixel in an image to the specified color.
     *
     * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL
     * @param color - new color for the pixels
     * @param x - left position of the pixel
     * @param y - top position of the pixel
     */
    extern void putPixelImage(Color color, int x, int y, Image* image);
    
    /**
     * Get the color of a pixel on screen.
     *
     * @pre x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT
     * @param x - left position of the pixel
     * @param y - top position of the pixel
     * @return the color of the pixel
     */
    extern Color getPixelScreen(int x, int y);
    
    /**
     * Get the color of a pixel of an image.
     *
     * @pre x >= 0 && x < image->imageWidth && y >= 0 && y < image->imageHeight && image != NULL
     * @param x - left position of the pixel
     * @param y - top position of the pixel
     * @return the color of the pixel
     */
    extern Color getPixelImage(int x, int y, Image* image);
    
    /**
     * Print a text (pixels out of the screen or image are clipped).
     *
     * @param x - left position of text
     * @param y - top position of text
     * @param text - the text to print
     * @param color - text color
     */
    extern void printTextScreen(int x, int y, const char* text, Color color);
    
    /**
     * Print a text (pixels out of the screen or image are clipped).
     *
     * @param x - left position of text
     * @param y - top position of text
     * @param text - the text to print
     * @param color - text color
     * @param image - image
     */
    extern void printTextImage(int x, int y, const char* text, Color color, Image* image);
    
    /**
     * Print a text, which was rendered to a bitmap with Freetype.
     *
     * @param x - left position of text
     * @param y - top position of text
     * @param text - the text to print
     * @param color - text color
     * @param image - image
     */
    extern void fontPrintTextImage(FT_Bitmap* bitmap, int x, int y, Color color, Image* image);
    
    /**
     * Print a text, which was rendered to a bitmap with Freetype.
     *
     * @param x - left position of text
     * @param y - top position of text
     * @param text - the text to print
     * @param color - text color
     */
    extern void fontPrintTextScreen(FT_Bitmap* bitmap, int x, int y, Color color);
    
    /**
     * Save an image or the screen in PNG or JPEG format (depends on the filename suffix).
     *
     * @pre filename != NULL
     * @param filename - filename of the PNG image
     * @param data - start of Color type pixel data (can be getVramDisplayBuffer())
     * @param width - logical width of the image or SCREEN_WIDTH
     * @param height - height of the image or SCREEN_HEIGHT
     * @param lineSize - physical width of the image or PSP_LINE_SIZE
     * @param saveAlpha - if 0, image is saved without alpha channel
     */
    extern void saveImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha);
    
    /**
     * Save an image or the screen in PNG format.
     *
     * @pre filename != NULL
     * @param filename - filename of the PNG image
     * @param data - start of Color type pixel data (can be getVramDisplayBuffer())
     * @param width - logical width of the image or SCREEN_WIDTH
     * @param height - height of the image or SCREEN_HEIGHT
     * @param lineSize - physical width of the image or PSP_LINE_SIZE
     * @param saveAlpha - if 0, image is saved without alpha channel
     */
    extern void savePngImage(const char* filename, Color* data, int width, int height, int lineSize, int saveAlpha);
    
    /**
     * Save an image or the screen in JPEG format.
     *
     * @pre filename != NULL
     * @param filename - filename of the JPEG image
     * @param data - start of Color type pixel data (can be getVramDisplayBuffer())
     * @param width - logical width of the image or SCREEN_WIDTH
     * @param height - height of the image or SCREEN_HEIGHT
     * @param lineSize - physical width of the image or PSP_LINE_SIZE
     */
    extern void saveJpegImage(const char* filename, Color* data, int width, int height, int lineSize);
    
    /**
     * Exchange display buffer and drawing buffer.
     */
    extern void flipScreen();
    
    /**
     * Initialize the graphics.
     */
    extern void initGraphics();
    
    /**
     * Disable graphics, used for debug text output.
     */
    extern void disableGraphics();
    
    /**
     * Draw a line to screen.
     *
     * @pre x0 >= 0 && x0 < SCREEN_WIDTH && y0 >= 0 && y0 < SCREEN_HEIGHT &&
     *      x1 >= 0 && x1 < SCREEN_WIDTH && y1 >= 0 && y1 < SCREEN_HEIGHT
     * @param x0 - x line start position
     * @param y0 - y line start position
     * @param x1 - x line end position
     * @param y1 - y line end position
     */
    void drawLineScreen(int x0, int y0, int x1, int y1, Color color);
    
    /**
     * Draw a line to screen.
     *
     * @pre x0 >= 0 && x0 < image->imageWidth && y0 >= 0 && y0 < image->imageHeight &&
     *      x1 >= 0 && x1 < image->imageWidth && y1 >= 0 && y1 < image->imageHeight
     * @param x0 - x line start position
     * @param y0 - y line start position
     * @param x1 - x line end position
     * @param y1 - y line end position
     */
    extern void drawLineImage(int x0, int y0, int x1, int y1, Color color, Image* image);
    
    /**
     * Get the current draw buffer for fast unchecked access.
     *
     * @return the start address of the current draw buffer
     */
    extern Color* getVramDrawBuffer();
    
    /**
     * Get the current display buffer for fast unchecked access.
     *
     * @return the start address of the current display buffer
     */
    extern Color* getVramDisplayBuffer();
    
    extern void guStart();
    
    #endif

    Spoiler for framebuffer.c:
    Code:
    #include <psptypes.h>
    //#include "graphics.h"
    
    u32* g_vram_base = (u32*) (0x40000000 | 0x04000000);

    Spoiler for framebuffer.h:
    Code:
    #ifndef FRAMEBUFFER_H
    #define FRAMEBUFFER_H
    
    #include <psptypes.h>
    
    extern u32* g_vram_base;
    
    #endif


    You can always remove the freetype/jpeg stuff if you don't need them, as they require extra libraries and make your ELF bigger.
    wheeee =:D

  15. #5595
    Heroes never die
    Points: 8.645, Level: 62
    Level completed: 65%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    ...........
    Beiträge
    1.323
    Points
    8.645
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    Code:
    int * pInt = (int*)(0×88000000);
    *pInt = 3;
    perfect , thnx

  16. #5596
    words are stones in my <3
    Points: 35.274, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Jul 2005
    Ort
    Spokane
    Beiträge
    5.008
    Points
    35.274
    Level
    100
    My Mood
    Lonely
    Downloads
    1
    Uploads
    0

    Standard

    Zitat Zitat von MiG
    exactly..

    void trace(char text[])

    would be better.
    ...
    Code:
    void trace(const char *text);
    ?

    ...at what speed must I live.. to be able to see you again?...

    Projects

    You can support my Open World 3D RPG for PSP by voting for it here


  17. #5597
    Points: 3.094, Level: 34
    Level completed: 30%, Points required for next Level: 106
    Overall activity: 0%

    Registriert seit
    Jul 2007
    Beiträge
    1
    Points
    3.094
    Level
    34
    Downloads
    0
    Uploads
    0

    Standard

    can anyone teach me how to code in lua because i dont know how and i want to lean

    by the way im fatboys bro

  18. #5598
    QJ Gamer Gold
    Points: 12.189, Level: 72
    Level completed: 35%, Points required for next Level: 261
    Overall activity: 0%

    Registriert seit
    Aug 2006
    Ort
    Under Your Bed
    Beiträge
    3.083
    Points
    12.189
    Level
    72
    Downloads
    0
    Uploads
    0

    Standard

    Wrong thread go to the Lua Help Thread... and post Lua things there

  19. #5599
    QJ Gamer Green
    Points: 9.165, Level: 64
    Level completed: 39%, Points required for next Level: 185
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Ort
    England ~¦¦¦|+|¦¦¦~
    Beiträge
    1.112
    Points
    9.165
    Level
    64
    My Mood
    Bored
    Downloads
    0
    Uploads
    0

    Standard

    I'm confused by different 'bits' of data. Where you have variables like 'u32', 'u16', 'u8'?

    im guessing they are something like this:
    Examples:
    u32: 0xFFFFFFFF
    u16: 0xFFFF
    u8: 0xFF

    But where and WHY would i use these values in a program? What are they used for? And why would i choose a u16 over a u32 for example?
    ...Just Returned To The Scene...

  20. #5600
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von JaSo PsP
    I'm confused by different 'bits' of data. Where you have variables like 'u32', 'u16', 'u8'?

    im guessing they are something like this:
    Examples:
    u32: 0xFFFFFFFF
    u16: 0xFFFF
    u8: 0xFF

    But where and WHY would i use these values in a program? What are they used for? And why would i choose a u16 over a u32 for example?
    These are usually typedef datatypes. A U32 usually means an unsigned integer that is 32 bits, S32 would be a signed int that is 32 bit etc. U8 would a be an unsigned integer that is 8 bit therefore it can only hold a value of 0-255.

    In some programs, you need to maximise the amount of space that you are using, for example say you are storing 4 values that you know will never be more then 255 and less then 0. If you did it like this:
    Code:
    int a, b, c, d;
    That would take up 4 * 32bits which is 128bits.

    If you declared them like this:
    Code:
    U8 a, b, c, d;
    The compiler *MAY* pack this into 32 bits (4 * 8). I really stress MAY here, the compiler might equally pad each variable with 24 bits so they are 4 byte (32 bits) aligned in memory and therefore use the same number of bits as 4 ints.

    At this stage, this isn't something you should worry about or spread information. It only really matters if you are REALLY having memory issues. As a rule of thumb in context of memory usage, ALWAYS use int or unsigned int.

    The other use of these datatypes is for pointer arithmetic especially when dealing with registers and hardware memory addresses.

    e.g.
    Code:
    int * pInt = (int*)(0x80);
    pInt++;
    // pInt now points to 0x00A0;
    
    U8 * pU8 = (U8*)(0x80);
    pU8++;
    // pU8 now points to 0x0088;
    Also, the pointer type represents how many bits at the memory address you modify when giving it a value.

    All of this is pretty low level and rarely gets used at all on gameplay logic level.

  21. #5601
    QJ Gamer Green
    Points: 9.165, Level: 64
    Level completed: 39%, Points required for next Level: 185
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Ort
    England ~¦¦¦|+|¦¦¦~
    Beiträge
    1.112
    Points
    9.165
    Level
    64
    My Mood
    Bored
    Downloads
    0
    Uploads
    0

    Standard

    thanks, i dont think i'll ever find a need to use these anyway. :P
    ...Just Returned To The Scene...

  22. #5602
    MiG
    MiG ist offline
    QJ Gamer Blue
    Points: 5.848, Level: 49
    Level completed: 49%, Points required for next Level: 102
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    499
    Points
    5.848
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von AdjutantReflex
    ...
    Code:
    void trace(const char *text);
    ?
    const, yesh that would be better, didn't notice he was only reading the array..
    an array of chars works good as pointer to the start of a char array.

    Myself, I think its a load of toss and the C++ & the String library should be used, much better.

  23. #5603
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Guys,

    I'm useing LTE 2.2, right? So, I'm coding a shell for myself, I'm trying to add a button, and when I use the code I need to add the button:

    " gui->addImage(menuicon, core:osition2d<s32>(0,0), 0, 101, 0); "

    I get this error:

    " main.cpp:202: error: expected primary-expression before "->" token. "

    Line 202 is the code I posted above.


    --------
    Here's the class refrence, if you need it:

    virtual IGUIImage * addImage (video::ITexture *image, core:osition2d< s32 > pos, bool useAlphaChannel=true, IGUIElement *parent=0, s32 id=-1, const wchar_t *text=0)=0
    Adds an image element.


    So what is my problem?
    ---------

  24. #5604
    QJ Gamer Green
    Points: 9.165, Level: 64
    Level completed: 39%, Points required for next Level: 185
    Overall activity: 0%

    Registriert seit
    Apr 2006
    Ort
    England ~¦¦¦|+|¦¦¦~
    Beiträge
    1.112
    Points
    9.165
    Level
    64
    My Mood
    Bored
    Downloads
    0
    Uploads
    0

    Standard

    Im not sure about your exact problem, but i looked that this in teh Hello World example:
    Code:
    gui::IGUIStaticText* statusText = guienv->addStaticText(L"Hello World!",
    		rect<int>(10,10,260,22), true);
    maybe it should look something like that? I dunno, i have been looking at this LTE package for about 10 mins.

    I also looked at IGUIImage.h:

    Code:
    namespace engine
    {
    namespace gui
    {
    
    	//! GUI element displaying an image.
    	class IGUIImage : public IGUIElement
    	{
    	public:
    
    		//! constructor
    		IGUIImage(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
    			: IGUIElement(EGUIET_IMAGE, environment, parent, id, rectangle) {}
    
    		//! destructor
    		~IGUIImage() {};
    
    		//! sets an image
    		virtual void setImage(video::ITexture* image) = 0;
    
    		//! sets if the image should use its alpha channel to draw itself
    		virtual void setUseAlphaChannel(bool use) = 0;
    	};
    
    
    } // end namespace gui
    } // end namespace engine
    ...Just Returned To The Scene...

  25. #5605
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    EDIT: Nvm, Fixed it.
    Geändert von MrChaos (07-21-2007 um 07:15 PM Uhr) Grund: Automerged Doublepost

  26. #5606
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    I'm having a problem, in my game every time I access the menu my game crashes, according to PSPLink, I have an FPU exception.

    I was just wondering if the FPU exception is due to a lack of memory? Or something else? The thread works fine when its loaded on its own, and only throws up this error when its loaded after the rest of the program, also if I remove the blitting process it works fine, but I can't understand why, as the images have already been loaded in memory by that time.

    Thanks or any help.
    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  27. #5607
    It's good to be free...
    Points: 10.420, Level: 67
    Level completed: 93%, Points required for next Level: 30
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    2.440
    Points
    10.420
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    And FPU exception means that something bad happened inside of the floating point unit. Generally, this is something like 1.0f/0.0f (division by zero error), which is of course impossible, but it can be other things, too.
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  28. #5608
    QJ Gamer Gold
    Points: 14.678, Level: 78
    Level completed: 57%, Points required for next Level: 172
    Overall activity: 0%

    Registriert seit
    Nov 2006
    Beiträge
    1.523
    Points
    14.678
    Level
    78
    Downloads
    0
    Uploads
    0

    Standard Speed Issue...

    Total 12 conditions:
    ---
    Which one is faster?

    If or else if
    or
    Switch

    Edit: I do see it's faster for X86 platform but for Mips?

  29. #5609
    QJ Gamer Green
    Points: 5.795, Level: 49
    Level completed: 23%, Points required for next Level: 155
    Overall activity: 0%

    Registriert seit
    Sep 2006
    Ort
    Cape Town, South Africa
    Beiträge
    714
    Points
    5.795
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    So do you have:
    Code:
    if (something == somethingElse) { ...
    } else if (something == somethingElse2) { ..
    } else if (something == somethingElse3) {...
    } ...
    with 12 "somethingElse"s? In that case, switch is faster, I'd imagine.

  30. #5610
    QJ Gamer Green
    Points: 8.459, Level: 62
    Level completed: 3%, Points required for next Level: 291
    Overall activity: 32,0%

    Registriert seit
    Apr 2007
    Beiträge
    886
    Points
    8.459
    Level
    62
    Downloads
    0
    Uploads
    0

    Standard

    can some1 up umd.h. i dont want to download the new toolchain just to get on header so can someone hook me up


 

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 09:28 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .