src/render/psp/SDL_render_psp.c
changeset 7191 75360622e65f
parent 7096 640f553441e4
child 7663 53fe1b64eb2d
     1.1 --- a/src/render/psp/SDL_render_psp.c	Sat May 18 12:48:50 2013 -0700
     1.2 +++ b/src/render/psp/SDL_render_psp.c	Sat May 18 14:17:52 2013 -0700
     1.3 @@ -20,7 +20,7 @@
     1.4  */
     1.5  #include "SDL_config.h"
     1.6  
     1.7 -#if SDL_VIDEO_RENDER_PSP 
     1.8 +#if SDL_VIDEO_RENDER_PSP
     1.9  
    1.10  #include "SDL_hints.h"
    1.11  #include "../SDL_sysrender.h"
    1.12 @@ -93,94 +93,94 @@
    1.13  };
    1.14  */
    1.15  SDL_RenderDriver PSP_RenderDriver = {
    1.16 -	.CreateRenderer = PSP_CreateRenderer,
    1.17 +    .CreateRenderer = PSP_CreateRenderer,
    1.18      .info = {
    1.19 -		.name = "PSP",
    1.20 -		.flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE,
    1.21 -		.num_texture_formats = 4,
    1.22 -		.texture_formats = { [0] = SDL_PIXELFORMAT_BGR565,
    1.23 -							 					 [1] = SDL_PIXELFORMAT_ABGR1555,
    1.24 -							 					 [2] = SDL_PIXELFORMAT_ABGR4444,
    1.25 -							 					 [3] = SDL_PIXELFORMAT_ABGR8888,
    1.26 -		},
    1.27 -		.max_texture_width = 512,
    1.28 -		.max_texture_height = 512,
    1.29 +        .name = "PSP",
    1.30 +        .flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE,
    1.31 +        .num_texture_formats = 4,
    1.32 +        .texture_formats = { [0] = SDL_PIXELFORMAT_BGR565,
    1.33 +                                                 [1] = SDL_PIXELFORMAT_ABGR1555,
    1.34 +                                                 [2] = SDL_PIXELFORMAT_ABGR4444,
    1.35 +                                                 [3] = SDL_PIXELFORMAT_ABGR8888,
    1.36 +        },
    1.37 +        .max_texture_width = 512,
    1.38 +        .max_texture_height = 512,
    1.39       }
    1.40  };
    1.41  
    1.42 -#define PSP_SCREEN_WIDTH	480
    1.43 -#define PSP_SCREEN_HEIGHT	272
    1.44 +#define PSP_SCREEN_WIDTH    480
    1.45 +#define PSP_SCREEN_HEIGHT   272
    1.46  
    1.47 -#define PSP_FRAME_BUFFER_WIDTH	512
    1.48 -#define PSP_FRAME_BUFFER_SIZE	(PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT)
    1.49 +#define PSP_FRAME_BUFFER_WIDTH  512
    1.50 +#define PSP_FRAME_BUFFER_SIZE   (PSP_FRAME_BUFFER_WIDTH*PSP_SCREEN_HEIGHT)
    1.51  
    1.52  static unsigned int __attribute__((aligned(16))) DisplayList[262144];
    1.53  
    1.54 -																						 	
    1.55 -#define COL5650(r,g,b,a)	((r>>3) | ((g>>2)<<5) | ((b>>3)<<11))
    1.56 -#define COL5551(r,g,b,a)	((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0))
    1.57 -#define COL4444(r,g,b,a)	((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12))
    1.58 -#define COL8888(r,g,b,a)	((r) | ((g)<<8) | ((b)<<16) | ((a)<<24))
    1.59 -	
    1.60 +
    1.61 +#define COL5650(r,g,b,a)    ((r>>3) | ((g>>2)<<5) | ((b>>3)<<11))
    1.62 +#define COL5551(r,g,b,a)    ((r>>3) | ((g>>3)<<5) | ((b>>3)<<10) | (a>0?0x7000:0))
    1.63 +#define COL4444(r,g,b,a)    ((r>>4) | ((g>>4)<<4) | ((b>>4)<<8) | ((a>>4)<<12))
    1.64 +#define COL8888(r,g,b,a)    ((r) | ((g)<<8) | ((b)<<16) | ((a)<<24))
    1.65 +
    1.66  
    1.67  typedef struct
    1.68  {
    1.69 -	void* 			frontbuffer ;
    1.70 -	void* 			backbuffer ;
    1.71 -	SDL_bool 		initialized ;
    1.72 -	SDL_bool 		displayListAvail ;
    1.73 -	unsigned int 	psm ;
    1.74 -	unsigned int 	bpp ;
    1.75 -	
    1.76 -	SDL_bool    	vsync;	
    1.77 -	unsigned int 	currentColor;
    1.78 -	int				currentBlendMode;
    1.79 -		
    1.80 +    void*           frontbuffer ;
    1.81 +    void*           backbuffer ;
    1.82 +    SDL_bool        initialized ;
    1.83 +    SDL_bool        displayListAvail ;
    1.84 +    unsigned int    psm ;
    1.85 +    unsigned int    bpp ;
    1.86 +
    1.87 +    SDL_bool        vsync;
    1.88 +    unsigned int    currentColor;
    1.89 +    int             currentBlendMode;
    1.90 +
    1.91  } PSP_RenderData;
    1.92  
    1.93  
    1.94  typedef struct
    1.95  {
    1.96 -	void				*data;								/**< Image data. */
    1.97 -	unsigned int		size;								/**< Size of data in bytes. */
    1.98 -	unsigned int		width;								/**< Image width. */
    1.99 -	unsigned int		height;								/**< Image height. */
   1.100 -	unsigned int		textureWidth;						/**< Texture width (power of two). */
   1.101 -	unsigned int		textureHeight;						/**< Texture height (power of two). */
   1.102 -	unsigned int		bits;								/**< Image bits per pixel. */
   1.103 -	unsigned int		format;								/**< Image format - one of ::pgePixelFormat. */
   1.104 -	unsigned int		pitch;										
   1.105 -	SDL_bool			swizzled;							/**< Is image swizzled. */
   1.106 +    void                *data;                              /**< Image data. */
   1.107 +    unsigned int        size;                               /**< Size of data in bytes. */
   1.108 +    unsigned int        width;                              /**< Image width. */
   1.109 +    unsigned int        height;                             /**< Image height. */
   1.110 +    unsigned int        textureWidth;                       /**< Texture width (power of two). */
   1.111 +    unsigned int        textureHeight;                      /**< Texture height (power of two). */
   1.112 +    unsigned int        bits;                               /**< Image bits per pixel. */
   1.113 +    unsigned int        format;                             /**< Image format - one of ::pgePixelFormat. */
   1.114 +    unsigned int        pitch;
   1.115 +    SDL_bool            swizzled;                           /**< Is image swizzled. */
   1.116  
   1.117  } PSP_TextureData;
   1.118  
   1.119  typedef struct
   1.120 -{	
   1.121 -	float	x, y, z;
   1.122 +{
   1.123 +    float   x, y, z;
   1.124  } VertV;
   1.125  
   1.126  
   1.127  typedef struct
   1.128  {
   1.129 -	float	u, v;
   1.130 -	float	x, y, z;
   1.131 -	
   1.132 +    float   u, v;
   1.133 +    float   x, y, z;
   1.134 +
   1.135  } VertTV;
   1.136  
   1.137  
   1.138 -// Return next power of 2
   1.139 -static int 
   1.140 +/* Return next power of 2 */
   1.141 +static int
   1.142  TextureNextPow2(unsigned int w)
   1.143  {
   1.144 -	if(w == 0)
   1.145 -		return 0;
   1.146 +    if(w == 0)
   1.147 +        return 0;
   1.148  
   1.149 -	unsigned int n = 2;
   1.150 +    unsigned int n = 2;
   1.151  
   1.152 -	while(w > n)
   1.153 -		n <<= 1;
   1.154 +    while(w > n)
   1.155 +        n <<= 1;
   1.156  
   1.157 -	return n;
   1.158 +    return n;
   1.159  }
   1.160  
   1.161  
   1.162 @@ -190,9 +190,9 @@
   1.163      const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
   1.164  
   1.165      if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
   1.166 -        return GU_NEAREST; // GU_NEAREST good for tile-map
   1.167 +        return GU_NEAREST; /* GU_NEAREST good for tile-map */
   1.168      } else {
   1.169 -        return GU_LINEAR; // GU_LINEAR good for scaling
   1.170 +        return GU_LINEAR; /* GU_LINEAR good for scaling */
   1.171      }
   1.172  }
   1.173  
   1.174 @@ -207,133 +207,133 @@
   1.175      case SDL_PIXELFORMAT_ABGR4444:
   1.176          return GU_PSM_4444;
   1.177      case SDL_PIXELFORMAT_ABGR8888:
   1.178 -        return GU_PSM_8888;        
   1.179 -    default:    	
   1.180 +        return GU_PSM_8888;
   1.181 +    default:
   1.182          return GU_PSM_8888;
   1.183      }
   1.184  }
   1.185  
   1.186 -void 
   1.187 +void
   1.188  StartDrawing(SDL_Renderer * renderer)
   1.189 -{	
   1.190 -	PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
   1.191 -	if(data->displayListAvail)
   1.192 -		return;
   1.193 +{
   1.194 +    PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
   1.195 +    if(data->displayListAvail)
   1.196 +        return;
   1.197  
   1.198 -	sceGuStart(GU_DIRECT, DisplayList);
   1.199 -	data->displayListAvail = SDL_TRUE;
   1.200 +    sceGuStart(GU_DIRECT, DisplayList);
   1.201 +    data->displayListAvail = SDL_TRUE;
   1.202  }
   1.203  
   1.204  
   1.205 -int 
   1.206 +int
   1.207  TextureSwizzle(PSP_TextureData *psp_texture)
   1.208  {
   1.209 -	if(psp_texture->swizzled)
   1.210 -		return 1;
   1.211 -	
   1.212 -	int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
   1.213 -	int height = psp_texture->size / bytewidth;
   1.214 +    if(psp_texture->swizzled)
   1.215 +        return 1;
   1.216 +
   1.217 +    int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
   1.218 +    int height = psp_texture->size / bytewidth;
   1.219  
   1.220 -	int rowblocks = (bytewidth>>4);
   1.221 -	int rowblocksadd = (rowblocks-1)<<7;
   1.222 -	unsigned int blockaddress = 0;
   1.223 -	unsigned int *src = (unsigned int*) psp_texture->data;
   1.224 +    int rowblocks = (bytewidth>>4);
   1.225 +    int rowblocksadd = (rowblocks-1)<<7;
   1.226 +    unsigned int blockaddress = 0;
   1.227 +    unsigned int *src = (unsigned int*) psp_texture->data;
   1.228  
   1.229 -	unsigned char *data = NULL;	
   1.230 -	data = malloc(psp_texture->size);
   1.231 +    unsigned char *data = NULL;
   1.232 +    data = malloc(psp_texture->size);
   1.233  
   1.234 -	int j;
   1.235 +    int j;
   1.236  
   1.237 -	for(j = 0; j < height; j++, blockaddress += 16)
   1.238 -	{
   1.239 -		unsigned int *block;
   1.240 +    for(j = 0; j < height; j++, blockaddress += 16)
   1.241 +    {
   1.242 +        unsigned int *block;
   1.243  
   1.244 -		block = (unsigned int*)&data[blockaddress];
   1.245 +        block = (unsigned int*)&data[blockaddress];
   1.246  
   1.247 -		int i;
   1.248 +        int i;
   1.249  
   1.250 -		for(i = 0; i < rowblocks; i++)
   1.251 -		{
   1.252 -			*block++ = *src++;
   1.253 -			*block++ = *src++;
   1.254 -			*block++ = *src++;
   1.255 -			*block++ = *src++;
   1.256 -			block += 28;
   1.257 -		}
   1.258 +        for(i = 0; i < rowblocks; i++)
   1.259 +        {
   1.260 +            *block++ = *src++;
   1.261 +            *block++ = *src++;
   1.262 +            *block++ = *src++;
   1.263 +            *block++ = *src++;
   1.264 +            block += 28;
   1.265 +        }
   1.266  
   1.267 -		if((j & 0x7) == 0x7)
   1.268 -			blockaddress += rowblocksadd;
   1.269 -	}
   1.270 +        if((j & 0x7) == 0x7)
   1.271 +            blockaddress += rowblocksadd;
   1.272 +    }
   1.273  
   1.274 -	free(psp_texture->data);	
   1.275 -	psp_texture->data = data;
   1.276 -	psp_texture->swizzled = SDL_TRUE;
   1.277 +    free(psp_texture->data);
   1.278 +    psp_texture->data = data;
   1.279 +    psp_texture->swizzled = SDL_TRUE;
   1.280  
   1.281 -	return 1;
   1.282 +    return 1;
   1.283  }
   1.284  int TextureUnswizzle(PSP_TextureData *psp_texture)
   1.285  {
   1.286 -	if(!psp_texture->swizzled)
   1.287 -		return 1;
   1.288 -		
   1.289 -	int blockx, blocky;
   1.290 -	
   1.291 -	int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
   1.292 -	int height = psp_texture->size / bytewidth;
   1.293 -	
   1.294 -	int widthblocks = bytewidth/16;
   1.295 -	int heightblocks = height/8;
   1.296 -	
   1.297 -	int dstpitch = (bytewidth - 16)/4;
   1.298 -	int dstrow = bytewidth * 8;
   1.299 +    if(!psp_texture->swizzled)
   1.300 +        return 1;
   1.301 +
   1.302 +    int blockx, blocky;
   1.303 +
   1.304 +    int bytewidth = psp_texture->textureWidth*(psp_texture->bits>>3);
   1.305 +    int height = psp_texture->size / bytewidth;
   1.306 +
   1.307 +    int widthblocks = bytewidth/16;
   1.308 +    int heightblocks = height/8;
   1.309 +
   1.310 +    int dstpitch = (bytewidth - 16)/4;
   1.311 +    int dstrow = bytewidth * 8;
   1.312  
   1.313 -	unsigned int *src = (unsigned int*) psp_texture->data;
   1.314 +    unsigned int *src = (unsigned int*) psp_texture->data;
   1.315  
   1.316 -	unsigned char *data = NULL;
   1.317 -	
   1.318 -	data = malloc(psp_texture->size);
   1.319 +    unsigned char *data = NULL;
   1.320 +
   1.321 +    data = malloc(psp_texture->size);
   1.322  
   1.323 -	if(!data)
   1.324 -		return 0;
   1.325 -		
   1.326 -	sceKernelDcacheWritebackAll();
   1.327 +    if(!data)
   1.328 +        return 0;
   1.329  
   1.330 -	int j;
   1.331 -	
   1.332 -	unsigned char *ydst = (unsigned char *)data;
   1.333 +    sceKernelDcacheWritebackAll();
   1.334 +
   1.335 +    int j;
   1.336 +
   1.337 +    unsigned char *ydst = (unsigned char *)data;
   1.338  
   1.339 -	for(blocky = 0; blocky < heightblocks; ++blocky)
   1.340 -	{
   1.341 -		unsigned char *xdst = ydst;
   1.342 -		
   1.343 -		for(blockx = 0; blockx < widthblocks; ++blockx)
   1.344 -		{
   1.345 -			unsigned int *block;
   1.346 +    for(blocky = 0; blocky < heightblocks; ++blocky)
   1.347 +    {
   1.348 +        unsigned char *xdst = ydst;
   1.349  
   1.350 -			block = (unsigned int*)xdst;
   1.351 +        for(blockx = 0; blockx < widthblocks; ++blockx)
   1.352 +        {
   1.353 +            unsigned int *block;
   1.354 +
   1.355 +            block = (unsigned int*)xdst;
   1.356  
   1.357 -			for(j = 0; j < 8; ++j)
   1.358 -			{
   1.359 -				*(block++) = *(src++);
   1.360 -				*(block++) = *(src++);
   1.361 -				*(block++) = *(src++);
   1.362 -				*(block++) = *(src++);
   1.363 -				block += dstpitch;
   1.364 -			}
   1.365 +            for(j = 0; j < 8; ++j)
   1.366 +            {
   1.367 +                *(block++) = *(src++);
   1.368 +                *(block++) = *(src++);
   1.369 +                *(block++) = *(src++);
   1.370 +                *(block++) = *(src++);
   1.371 +                block += dstpitch;
   1.372 +            }
   1.373  
   1.374 -			xdst += 16;
   1.375 -		}
   1.376 -		
   1.377 -		ydst += dstrow;
   1.378 -	}
   1.379 +            xdst += 16;
   1.380 +        }
   1.381 +
   1.382 +        ydst += dstrow;
   1.383 +    }
   1.384  
   1.385 -	free(psp_texture->data);
   1.386 -	
   1.387 -	psp_texture->data = data;
   1.388 +    free(psp_texture->data);
   1.389 +
   1.390 +    psp_texture->data = data;
   1.391  
   1.392 -	psp_texture->swizzled = SDL_FALSE;
   1.393 +    psp_texture->swizzled = SDL_FALSE;
   1.394  
   1.395 -	return 1;
   1.396 +    return 1;
   1.397  }
   1.398  
   1.399  SDL_Renderer *
   1.400 @@ -342,7 +342,7 @@
   1.401  
   1.402      SDL_Renderer *renderer;
   1.403      PSP_RenderData *data;
   1.404 -		int pixelformat;
   1.405 +        int pixelformat;
   1.406      renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   1.407      if (!renderer) {
   1.408          SDL_OutOfMemory();
   1.409 @@ -355,8 +355,8 @@
   1.410          SDL_OutOfMemory();
   1.411          return NULL;
   1.412      }
   1.413 -    
   1.414 -		
   1.415 +
   1.416 +
   1.417      renderer->WindowEvent = PSP_WindowEvent;
   1.418      renderer->CreateTexture = PSP_CreateTexture;
   1.419      renderer->UpdateTexture = PSP_UpdateTexture;
   1.420 @@ -378,73 +378,73 @@
   1.421      renderer->info.flags = SDL_RENDERER_ACCELERATED;
   1.422      renderer->driverdata = data;
   1.423      renderer->window = window;
   1.424 -    
   1.425 -	if (data->initialized != SDL_FALSE)
   1.426 -		return 0;
   1.427 -	data->initialized = SDL_TRUE;
   1.428 -	
   1.429 +
   1.430 +    if (data->initialized != SDL_FALSE)
   1.431 +        return 0;
   1.432 +    data->initialized = SDL_TRUE;
   1.433 +
   1.434      if (flags & SDL_RENDERER_PRESENTVSYNC) {
   1.435          data->vsync = SDL_TRUE;
   1.436      } else {
   1.437          data->vsync = SDL_FALSE;
   1.438      }
   1.439 -    	
   1.440 -	pixelformat=PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window));
   1.441 -	switch(pixelformat)
   1.442 -	{
   1.443 -		case GU_PSM_4444:
   1.444 -		case GU_PSM_5650:
   1.445 -		case GU_PSM_5551:
   1.446 -			data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1);
   1.447 -			data->backbuffer =  (unsigned int *)(0);
   1.448 -			data->bpp = 2;
   1.449 -			data->psm = pixelformat;
   1.450 -			break;
   1.451 -		default:
   1.452 -			data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2);
   1.453 -			data->backbuffer =  (unsigned int *)(0);
   1.454 -			data->bpp = 4;
   1.455 -			data->psm = GU_PSM_8888;
   1.456 -			break;
   1.457 -	}
   1.458 -	
   1.459 -	sceGuInit();
   1.460 -	// setup GU
   1.461 -	sceGuStart(GU_DIRECT, DisplayList);
   1.462 -	sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH);
   1.463 -	sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH);
   1.464 +
   1.465 +    pixelformat=PixelFormatToPSPFMT(SDL_GetWindowPixelFormat(window));
   1.466 +    switch(pixelformat)
   1.467 +    {
   1.468 +        case GU_PSM_4444:
   1.469 +        case GU_PSM_5650:
   1.470 +        case GU_PSM_5551:
   1.471 +            data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<1);
   1.472 +            data->backbuffer =  (unsigned int *)(0);
   1.473 +            data->bpp = 2;
   1.474 +            data->psm = pixelformat;
   1.475 +            break;
   1.476 +        default:
   1.477 +            data->frontbuffer = (unsigned int *)(PSP_FRAME_BUFFER_SIZE<<2);
   1.478 +            data->backbuffer =  (unsigned int *)(0);
   1.479 +            data->bpp = 4;
   1.480 +            data->psm = GU_PSM_8888;
   1.481 +            break;
   1.482 +    }
   1.483 +
   1.484 +    sceGuInit();
   1.485 +    /* setup GU */
   1.486 +    sceGuStart(GU_DIRECT, DisplayList);
   1.487 +    sceGuDrawBuffer(data->psm, data->frontbuffer, PSP_FRAME_BUFFER_WIDTH);
   1.488 +    sceGuDispBuffer(PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT, data->backbuffer, PSP_FRAME_BUFFER_WIDTH);
   1.489  
   1.490  
   1.491 -	sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1));
   1.492 -	sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
   1.493 +    sceGuOffset(2048 - (PSP_SCREEN_WIDTH>>1), 2048 - (PSP_SCREEN_HEIGHT>>1));
   1.494 +    sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
   1.495  
   1.496      data->frontbuffer = vabsptr(data->frontbuffer);
   1.497      data->backbuffer = vabsptr(data->backbuffer);
   1.498 -    
   1.499 -	// Scissoring
   1.500 -	sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
   1.501 -	sceGuEnable(GU_SCISSOR_TEST);
   1.502 +
   1.503 +    /* Scissoring */
   1.504 +    sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
   1.505 +    sceGuEnable(GU_SCISSOR_TEST);
   1.506 +
   1.507 +    /* Backface culling */
   1.508 +    sceGuFrontFace(GU_CCW);
   1.509 +    sceGuEnable(GU_CULL_FACE);
   1.510  
   1.511 -	// Backface culling
   1.512 -	sceGuFrontFace(GU_CCW);
   1.513 -	sceGuEnable(GU_CULL_FACE);
   1.514 -	
   1.515 -	// Texturing
   1.516 -	sceGuEnable(GU_TEXTURE_2D);
   1.517 -	sceGuShadeModel(GU_SMOOTH);
   1.518 -	sceGuTexWrap(GU_REPEAT, GU_REPEAT);
   1.519 -	
   1.520 -	// Blending
   1.521 -	sceGuEnable(GU_BLEND);
   1.522 -	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
   1.523 +    /* Texturing */
   1.524 +    sceGuEnable(GU_TEXTURE_2D);
   1.525 +    sceGuShadeModel(GU_SMOOTH);
   1.526 +    sceGuTexWrap(GU_REPEAT, GU_REPEAT);
   1.527  
   1.528 -	sceGuTexFilter(GU_LINEAR,GU_LINEAR);
   1.529 -	
   1.530 -	sceGuFinish();
   1.531 -	sceGuSync(0,0);	
   1.532 -	sceDisplayWaitVblankStartCB();
   1.533 -	sceGuDisplay(GU_TRUE);	
   1.534 -		
   1.535 +    /* Blending */
   1.536 +    sceGuEnable(GU_BLEND);
   1.537 +    sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
   1.538 +
   1.539 +    sceGuTexFilter(GU_LINEAR,GU_LINEAR);
   1.540 +
   1.541 +    sceGuFinish();
   1.542 +    sceGuSync(0,0);
   1.543 +    sceDisplayWaitVblankStartCB();
   1.544 +    sceGuDisplay(GU_TRUE);
   1.545 +
   1.546      return renderer;
   1.547  }
   1.548  
   1.549 @@ -458,69 +458,69 @@
   1.550  static int
   1.551  PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   1.552  {
   1.553 -//		PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
   1.554 -	PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture));;
   1.555 -	
   1.556 -	if(!psp_texture)
   1.557 -		return -1;
   1.558 +//      PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
   1.559 +    PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture));;
   1.560 +
   1.561 +    if(!psp_texture)
   1.562 +        return -1;
   1.563  
   1.564 -	psp_texture->swizzled = SDL_FALSE;
   1.565 -	psp_texture->width = texture->w;
   1.566 -	psp_texture->height = texture->h;
   1.567 -	psp_texture->textureHeight = TextureNextPow2(texture->h);
   1.568 -	psp_texture->textureWidth = TextureNextPow2(texture->w);
   1.569 -	psp_texture->format = PixelFormatToPSPFMT(texture->format);
   1.570 +    psp_texture->swizzled = SDL_FALSE;
   1.571 +    psp_texture->width = texture->w;
   1.572 +    psp_texture->height = texture->h;
   1.573 +    psp_texture->textureHeight = TextureNextPow2(texture->h);
   1.574 +    psp_texture->textureWidth = TextureNextPow2(texture->w);
   1.575 +    psp_texture->format = PixelFormatToPSPFMT(texture->format);
   1.576  
   1.577 -	switch(psp_texture->format)
   1.578 -	{
   1.579 -		case GU_PSM_5650:
   1.580 -		case GU_PSM_5551:
   1.581 -		case GU_PSM_4444:
   1.582 -			psp_texture->bits = 16;
   1.583 -			break;
   1.584 -			
   1.585 -		case GU_PSM_8888:
   1.586 -			psp_texture->bits = 32;
   1.587 -			break;
   1.588 -			
   1.589 -		default:
   1.590 -			return -1;
   1.591 -	}
   1.592 +    switch(psp_texture->format)
   1.593 +    {
   1.594 +        case GU_PSM_5650:
   1.595 +        case GU_PSM_5551:
   1.596 +        case GU_PSM_4444:
   1.597 +            psp_texture->bits = 16;
   1.598 +            break;
   1.599 +
   1.600 +        case GU_PSM_8888:
   1.601 +            psp_texture->bits = 32;
   1.602 +            break;
   1.603  
   1.604 -	psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format);	
   1.605 -	psp_texture->size = psp_texture->textureHeight*psp_texture->pitch;
   1.606 -	psp_texture->data = SDL_calloc(1, psp_texture->size);
   1.607 -	
   1.608 -	if(!psp_texture->data)
   1.609 -	{
   1.610 -		SDL_free(psp_texture);
   1.611 -		return SDL_OutOfMemory();
   1.612 -	}
   1.613 +        default:
   1.614 +            return -1;
   1.615 +    }
   1.616 +
   1.617 +    psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format);
   1.618 +    psp_texture->size = psp_texture->textureHeight*psp_texture->pitch;
   1.619 +    psp_texture->data = SDL_calloc(1, psp_texture->size);
   1.620 +
   1.621 +    if(!psp_texture->data)
   1.622 +    {
   1.623 +        SDL_free(psp_texture);
   1.624 +        return SDL_OutOfMemory();
   1.625 +    }
   1.626      texture->driverdata = psp_texture;
   1.627 -    
   1.628 +
   1.629      return 0;
   1.630  }
   1.631  
   1.632  
   1.633 -void 
   1.634 +void
   1.635  TextureActivate(SDL_Texture * texture)
   1.636 -{		
   1.637 -	PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
   1.638 -	int scaleMode = GetScaleQuality();
   1.639 -	
   1.640 -	// Swizzling is useless with small textures.
   1.641 +{
   1.642 +    PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
   1.643 +    int scaleMode = GetScaleQuality();
   1.644 +
   1.645 +    /* Swizzling is useless with small textures. */
   1.646      if (texture->w >= 16 || texture->h >= 16)
   1.647      {
   1.648 -		TextureSwizzle(psp_texture);	
   1.649 +        TextureSwizzle(psp_texture);
   1.650      }
   1.651 -    
   1.652 -	sceGuEnable(GU_TEXTURE_2D);
   1.653 -	sceGuTexWrap(GU_REPEAT, GU_REPEAT);
   1.654 -	sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled);
   1.655 -	sceGuTexFilter(scaleMode, scaleMode); // GU_NEAREST good for tile-map
   1.656 -										  // GU_LINEAR good for scaling	
   1.657 -	sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data);
   1.658 -	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
   1.659 +
   1.660 +    sceGuEnable(GU_TEXTURE_2D);
   1.661 +    sceGuTexWrap(GU_REPEAT, GU_REPEAT);
   1.662 +    sceGuTexMode(psp_texture->format, 0, 0, psp_texture->swizzled);
   1.663 +    sceGuTexFilter(scaleMode, scaleMode); /* GU_NEAREST good for tile-map */
   1.664 +                                          /* GU_LINEAR good for scaling */
   1.665 +    sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data);
   1.666 +    sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
   1.667  }
   1.668  
   1.669  
   1.670 @@ -528,12 +528,12 @@
   1.671  PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   1.672                     const SDL_Rect * rect, const void *pixels, int pitch)
   1.673  {
   1.674 -//	PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
   1.675 +//  PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
   1.676      const Uint8 *src;
   1.677      Uint8 *dst;
   1.678      int row, length,dpitch;
   1.679      src = pixels;
   1.680 -    
   1.681 +
   1.682      PSP_LockTexture(renderer, texture,rect,(void **)&dst, &dpitch);
   1.683      length = rect->w * SDL_BYTESPERPIXEL(texture->format);
   1.684      if (length == pitch && length == dpitch) {
   1.685 @@ -545,8 +545,8 @@
   1.686              dst += dpitch;
   1.687          }
   1.688      }
   1.689 -    
   1.690 -	sceKernelDcacheWritebackAll();
   1.691 +
   1.692 +    sceKernelDcacheWritebackAll();
   1.693      return 0;
   1.694  }
   1.695  
   1.696 @@ -554,7 +554,7 @@
   1.697  PSP_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   1.698                   const SDL_Rect * rect, void **pixels, int *pitch)
   1.699  {
   1.700 -	PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
   1.701 +    PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
   1.702  
   1.703      *pixels =
   1.704          (void *) ((Uint8 *) psp_texture->data + rect->y * psp_texture->pitch +
   1.705 @@ -566,7 +566,7 @@
   1.706  static void
   1.707  PSP_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   1.708  {
   1.709 -	PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
   1.710 +    PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
   1.711      SDL_Rect rect;
   1.712  
   1.713      /* We do whole texture updates, at least for now */
   1.714 @@ -595,27 +595,27 @@
   1.715  static void
   1.716  PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode)
   1.717  {
   1.718 -	PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;				
   1.719 +    PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
   1.720      if (blendMode != data-> currentBlendMode) {
   1.721          switch (blendMode) {
   1.722          case SDL_BLENDMODE_NONE:
   1.723 -        		sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);        
   1.724 -				sceGuDisable(GU_BLEND);
   1.725 +                sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
   1.726 +                sceGuDisable(GU_BLEND);
   1.727              break;
   1.728          case SDL_BLENDMODE_BLEND:
   1.729 -        		sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
   1.730 -				sceGuEnable(GU_BLEND);
   1.731 -				sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
   1.732 +                sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
   1.733 +                sceGuEnable(GU_BLEND);
   1.734 +                sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );
   1.735              break;
   1.736          case SDL_BLENDMODE_ADD:
   1.737 -        		sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
   1.738 -				sceGuEnable(GU_BLEND);
   1.739 -				sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF );
   1.740 +                sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
   1.741 +                sceGuEnable(GU_BLEND);
   1.742 +                sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_FIX, 0, 0x00FFFFFF );
   1.743              break;
   1.744          case SDL_BLENDMODE_MOD:
   1.745 -        		sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
   1.746 -				sceGuEnable(GU_BLEND);
   1.747 -				sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
   1.748 +                sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
   1.749 +                sceGuEnable(GU_BLEND);
   1.750 +                sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
   1.751              break;
   1.752          }
   1.753          data->currentBlendMode = blendMode;
   1.754 @@ -626,13 +626,13 @@
   1.755  
   1.756  static int
   1.757  PSP_RenderClear(SDL_Renderer * renderer)
   1.758 -{					
   1.759 -		//start list
   1.760 -	StartDrawing(renderer);
   1.761 -	int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;		
   1.762 -	sceGuClearColor(color);
   1.763 -	sceGuClearDepth(0);
   1.764 -	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT);
   1.765 +{
   1.766 +    /* start list */
   1.767 +    StartDrawing(renderer);
   1.768 +    int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
   1.769 +    sceGuClearColor(color);
   1.770 +    sceGuClearDepth(0);
   1.771 +    sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT|GU_FAST_CLEAR_BIT);
   1.772  
   1.773      return 0;
   1.774  }
   1.775 @@ -641,22 +641,22 @@
   1.776  PSP_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
   1.777                        int count)
   1.778  {
   1.779 -	int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
   1.780 -	int i;
   1.781 -	StartDrawing(renderer);		
   1.782 -	VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV)); 
   1.783 -	
   1.784 - 	for (i = 0; i < count; ++i) {
   1.785 -			vertices[i].x = points[i].x;
   1.786 -			vertices[i].y = points[i].y;
   1.787 -			vertices[i].z = 0.0f;
   1.788 -	}
   1.789 -	sceGuDisable(GU_TEXTURE_2D);
   1.790 -	sceGuColor(color);		
   1.791 -	sceGuShadeModel(GU_FLAT);
   1.792 -	sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
   1.793 -	sceGuShadeModel(GU_SMOOTH);
   1.794 -	sceGuEnable(GU_TEXTURE_2D);			
   1.795 +    int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
   1.796 +    int i;
   1.797 +    StartDrawing(renderer);
   1.798 +    VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
   1.799 +
   1.800 +    for (i = 0; i < count; ++i) {
   1.801 +            vertices[i].x = points[i].x;
   1.802 +            vertices[i].y = points[i].y;
   1.803 +            vertices[i].z = 0.0f;
   1.804 +    }
   1.805 +    sceGuDisable(GU_TEXTURE_2D);
   1.806 +    sceGuColor(color);
   1.807 +    sceGuShadeModel(GU_FLAT);
   1.808 +    sceGuDrawArray(GU_POINTS, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
   1.809 +    sceGuShadeModel(GU_SMOOTH);
   1.810 +    sceGuEnable(GU_TEXTURE_2D);
   1.811  
   1.812      return 0;
   1.813  }
   1.814 @@ -665,24 +665,24 @@
   1.815  PSP_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
   1.816                       int count)
   1.817  {
   1.818 -	int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
   1.819 -	int i;
   1.820 -	StartDrawing(renderer);
   1.821 -	VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV)); 
   1.822 -	
   1.823 -	for (i = 0; i < count; ++i) {
   1.824 -			vertices[i].x = points[i].x;
   1.825 -			vertices[i].y = points[i].y;
   1.826 -			vertices[i].z = 0.0f;
   1.827 -	}
   1.828 +    int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
   1.829 +    int i;
   1.830 +    StartDrawing(renderer);
   1.831 +    VertV* vertices = (VertV*)sceGuGetMemory(count*sizeof(VertV));
   1.832  
   1.833 -	sceGuDisable(GU_TEXTURE_2D);
   1.834 -	sceGuColor(color);
   1.835 -	sceGuShadeModel(GU_FLAT);
   1.836 -	sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
   1.837 -	sceGuShadeModel(GU_SMOOTH);
   1.838 -	sceGuEnable(GU_TEXTURE_2D);
   1.839 -	 
   1.840 +    for (i = 0; i < count; ++i) {
   1.841 +            vertices[i].x = points[i].x;
   1.842 +            vertices[i].y = points[i].y;
   1.843 +            vertices[i].z = 0.0f;
   1.844 +    }
   1.845 +
   1.846 +    sceGuDisable(GU_TEXTURE_2D);
   1.847 +    sceGuColor(color);
   1.848 +    sceGuShadeModel(GU_FLAT);
   1.849 +    sceGuDrawArray(GU_LINE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_2D, count, 0, vertices);
   1.850 +    sceGuShadeModel(GU_SMOOTH);
   1.851 +    sceGuEnable(GU_TEXTURE_2D);
   1.852 +
   1.853      return 0;
   1.854  }
   1.855  
   1.856 @@ -690,29 +690,29 @@
   1.857  PSP_RenderFillRects(SDL_Renderer * renderer, const SDL_FRect * rects,
   1.858                       int count)
   1.859  {
   1.860 -	int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
   1.861 -	int i;	
   1.862 -	StartDrawing(renderer);
   1.863 -	
   1.864 -	for (i = 0; i < count; ++i) {
   1.865 -    	const SDL_FRect *rect = &rects[i];
   1.866 -		VertV* vertices = (VertV*)sceGuGetMemory((sizeof(VertV)<<1));
   1.867 -		vertices[0].x = rect->x;
   1.868 -		vertices[0].y = rect->y;
   1.869 -		vertices[0].z = 0.0f;
   1.870 +    int color = renderer->a << 24 | renderer->b << 16 | renderer->g << 8 | renderer->r;
   1.871 +    int i;
   1.872 +    StartDrawing(renderer);
   1.873 +
   1.874 +    for (i = 0; i < count; ++i) {
   1.875 +        const SDL_FRect *rect = &rects[i];
   1.876 +        VertV* vertices = (VertV*)sceGuGetMemory((sizeof(VertV)<<1));
   1.877 +        vertices[0].x = rect->x;
   1.878 +        vertices[0].y = rect->y;
   1.879 +        vertices[0].z = 0.0f;
   1.880  
   1.881 -		vertices[1].x = rect->x + rect->w;
   1.882 -		vertices[1].y = rect->y + rect->h;
   1.883 -		vertices[1].z = 0.0f;
   1.884 -		
   1.885 -		sceGuDisable(GU_TEXTURE_2D);
   1.886 -		sceGuColor(color);			
   1.887 -		sceGuShadeModel(GU_FLAT);
   1.888 -		sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
   1.889 -		sceGuShadeModel(GU_SMOOTH);
   1.890 -		sceGuEnable(GU_TEXTURE_2D);
   1.891 +        vertices[1].x = rect->x + rect->w;
   1.892 +        vertices[1].y = rect->y + rect->h;
   1.893 +        vertices[1].z = 0.0f;
   1.894 +
   1.895 +        sceGuDisable(GU_TEXTURE_2D);
   1.896 +        sceGuColor(color);
   1.897 +        sceGuShadeModel(GU_FLAT);
   1.898 +        sceGuDrawArray(GU_SPRITES, GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
   1.899 +        sceGuShadeModel(GU_SMOOTH);
   1.900 +        sceGuEnable(GU_TEXTURE_2D);
   1.901      }
   1.902 -		
   1.903 +
   1.904      return 0;
   1.905  }
   1.906  
   1.907 @@ -724,127 +724,127 @@
   1.908  
   1.909  float MathAbs(float x)
   1.910  {
   1.911 -	float result;
   1.912 +    float result;
   1.913  
   1.914 -	__asm__ volatile (
   1.915 -		"mtv      %1, S000\n"
   1.916 -		"vabs.s   S000, S000\n"
   1.917 -		"mfv      %0, S000\n"
   1.918 -	: "=r"(result) : "r"(x));
   1.919 +    __asm__ volatile (
   1.920 +        "mtv      %1, S000\n"
   1.921 +        "vabs.s   S000, S000\n"
   1.922 +        "mfv      %0, S000\n"
   1.923 +    : "=r"(result) : "r"(x));
   1.924  
   1.925 -	return result;
   1.926 +    return result;
   1.927  }
   1.928  
   1.929  void MathSincos(float r, float *s, float *c)
   1.930  {
   1.931 -	__asm__ volatile (
   1.932 -		"mtv      %2, S002\n"
   1.933 -		"vcst.s   S003, VFPU_2_PI\n"
   1.934 -		"vmul.s   S002, S002, S003\n"
   1.935 -		"vrot.p   C000, S002, [s, c]\n"
   1.936 -		"mfv      %0, S000\n"
   1.937 -		"mfv      %1, S001\n"
   1.938 -	: "=r"(*s), "=r"(*c): "r"(r));
   1.939 +    __asm__ volatile (
   1.940 +        "mtv      %2, S002\n"
   1.941 +        "vcst.s   S003, VFPU_2_PI\n"
   1.942 +        "vmul.s   S002, S002, S003\n"
   1.943 +        "vrot.p   C000, S002, [s, c]\n"
   1.944 +        "mfv      %0, S000\n"
   1.945 +        "mfv      %1, S001\n"
   1.946 +    : "=r"(*s), "=r"(*c): "r"(r));
   1.947  }
   1.948  
   1.949  void Swap(float *a, float *b)
   1.950  {
   1.951 -	float n=*a;
   1.952 -	*a = *b;
   1.953 -	*b = n;
   1.954 +    float n=*a;
   1.955 +    *a = *b;
   1.956 +    *b = n;
   1.957  }
   1.958  
   1.959  static int
   1.960  PSP_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   1.961                  const SDL_Rect * srcrect, const SDL_FRect * dstrect)
   1.962  {
   1.963 -	float x, y, width, height;
   1.964 -	float u0, v0, u1, v1;
   1.965 -	unsigned char alpha;
   1.966 -	
   1.967 -	x = dstrect->x;
   1.968 -	y = dstrect->y;
   1.969 -	width = dstrect->w;
   1.970 -	height = dstrect->h;
   1.971 +    float x, y, width, height;
   1.972 +    float u0, v0, u1, v1;
   1.973 +    unsigned char alpha;
   1.974 +
   1.975 +    x = dstrect->x;
   1.976 +    y = dstrect->y;
   1.977 +    width = dstrect->w;
   1.978 +    height = dstrect->h;
   1.979 +
   1.980 +    u0 = srcrect->x;
   1.981 +    v0 = srcrect->y;
   1.982 +    u1 = srcrect->x + srcrect->w;
   1.983 +    v1 = srcrect->y + srcrect->h;
   1.984 +
   1.985 +    alpha = texture->a;
   1.986  
   1.987 -	u0 = srcrect->x;
   1.988 -	v0 = srcrect->y;
   1.989 -	u1 = srcrect->x + srcrect->w;
   1.990 -	v1 = srcrect->y + srcrect->h;
   1.991 -	
   1.992 -	alpha = texture->a;
   1.993 -	
   1.994 -	StartDrawing(renderer);
   1.995 -	TextureActivate(texture);
   1.996 -	PSP_SetBlendMode(renderer, renderer->blendMode);
   1.997 -	
   1.998 -	if(alpha != 255)
   1.999 -	{
  1.1000 -		sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
  1.1001 -		sceGuColor(GU_RGBA(255, 255, 255, alpha));
  1.1002 -	}else{
  1.1003 -		sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
  1.1004 -		sceGuColor(0xFFFFFFFF);
  1.1005 -	}
  1.1006 -		
  1.1007 -	if((MathAbs(u1) - MathAbs(u0)) < 64.0f)
  1.1008 -	{
  1.1009 -		VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
  1.1010 +    StartDrawing(renderer);
  1.1011 +    TextureActivate(texture);
  1.1012 +    PSP_SetBlendMode(renderer, renderer->blendMode);
  1.1013  
  1.1014 -		vertices[0].u = u0;
  1.1015 -		vertices[0].v = v0;
  1.1016 -		vertices[0].x = x;
  1.1017 -		vertices[0].y = y; 
  1.1018 -		vertices[0].z = 0;
  1.1019 +    if(alpha != 255)
  1.1020 +    {
  1.1021 +        sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
  1.1022 +        sceGuColor(GU_RGBA(255, 255, 255, alpha));
  1.1023 +    }else{
  1.1024 +        sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
  1.1025 +        sceGuColor(0xFFFFFFFF);
  1.1026 +    }
  1.1027 +
  1.1028 +    if((MathAbs(u1) - MathAbs(u0)) < 64.0f)
  1.1029 +    {
  1.1030 +        VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
  1.1031 +
  1.1032 +        vertices[0].u = u0;
  1.1033 +        vertices[0].v = v0;
  1.1034 +        vertices[0].x = x;
  1.1035 +        vertices[0].y = y;
  1.1036 +        vertices[0].z = 0;
  1.1037  
  1.1038 -		vertices[1].u = u1;
  1.1039 -		vertices[1].v = v1;
  1.1040 -		vertices[1].x = x + width;
  1.1041 -		vertices[1].y = y + height;
  1.1042 -		vertices[1].z = 0;
  1.1043 +        vertices[1].u = u1;
  1.1044 +        vertices[1].v = v1;
  1.1045 +        vertices[1].x = x + width;
  1.1046 +        vertices[1].y = y + height;
  1.1047 +        vertices[1].z = 0;
  1.1048  
  1.1049 -		sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
  1.1050 -	}
  1.1051 -	else
  1.1052 -	{
  1.1053 -		float start, end;
  1.1054 -		float curU = u0;
  1.1055 -		float curX = x;
  1.1056 -		float endX = x + width;
  1.1057 -		float slice = 64.0f;
  1.1058 -		float ustep = (u1 - u0)/width * slice;
  1.1059 -	
  1.1060 -		if(ustep < 0.0f)
  1.1061 -			ustep = -ustep;
  1.1062 +        sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
  1.1063 +    }
  1.1064 +    else
  1.1065 +    {
  1.1066 +        float start, end;
  1.1067 +        float curU = u0;
  1.1068 +        float curX = x;
  1.1069 +        float endX = x + width;
  1.1070 +        float slice = 64.0f;
  1.1071 +        float ustep = (u1 - u0)/width * slice;
  1.1072  
  1.1073 -		for(start = 0, end = width; start < end; start += slice)
  1.1074 -		{
  1.1075 -			VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
  1.1076 +        if(ustep < 0.0f)
  1.1077 +            ustep = -ustep;
  1.1078 +
  1.1079 +        for(start = 0, end = width; start < end; start += slice)
  1.1080 +        {
  1.1081 +            VertTV* vertices = (VertTV*)sceGuGetMemory((sizeof(VertTV))<<1);
  1.1082  
  1.1083 -			float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice;
  1.1084 -			float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep;
  1.1085 +            float polyWidth = ((curX + slice) > endX) ? (endX - curX) : slice;
  1.1086 +            float sourceWidth = ((curU + ustep) > u1) ? (u1 - curU) : ustep;
  1.1087  
  1.1088 -			vertices[0].u = curU;
  1.1089 -			vertices[0].v = v0;
  1.1090 -			vertices[0].x = curX;
  1.1091 -			vertices[0].y = y; 
  1.1092 -			vertices[0].z = 0;
  1.1093 +            vertices[0].u = curU;
  1.1094 +            vertices[0].v = v0;
  1.1095 +            vertices[0].x = curX;
  1.1096 +            vertices[0].y = y;
  1.1097 +            vertices[0].z = 0;
  1.1098  
  1.1099 -			curU += sourceWidth;
  1.1100 -			curX += polyWidth;
  1.1101 +            curU += sourceWidth;
  1.1102 +            curX += polyWidth;
  1.1103  
  1.1104 -			vertices[1].u = curU;
  1.1105 -			vertices[1].v = v1;
  1.1106 -			vertices[1].x = curX;
  1.1107 -			vertices[1].y = (y + height);
  1.1108 -			vertices[1].z = 0;
  1.1109 +            vertices[1].u = curU;
  1.1110 +            vertices[1].v = v1;
  1.1111 +            vertices[1].x = curX;
  1.1112 +            vertices[1].y = (y + height);
  1.1113 +            vertices[1].z = 0;
  1.1114  
  1.1115 -			sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
  1.1116 -		}
  1.1117 -	}
  1.1118 -	
  1.1119 -	if(alpha != 255)
  1.1120 -		sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
  1.1121 +            sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 2, 0, vertices);
  1.1122 +        }
  1.1123 +    }
  1.1124 +
  1.1125 +    if(alpha != 255)
  1.1126 +        sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
  1.1127      return 0;
  1.1128  }
  1.1129  
  1.1130 @@ -853,7 +853,7 @@
  1.1131                      Uint32 pixel_format, void * pixels, int pitch)
  1.1132  
  1.1133  {
  1.1134 -		return 0;
  1.1135 +        return 0;
  1.1136  }
  1.1137  
  1.1138  
  1.1139 @@ -862,98 +862,98 @@
  1.1140                  const SDL_Rect * srcrect, const SDL_FRect * dstrect,
  1.1141                  const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
  1.1142  {
  1.1143 -	float x, y, width, height;
  1.1144 -	float u0, v0, u1, v1;
  1.1145 -	unsigned char alpha;
  1.1146 -	float centerx, centery;
  1.1147 -	
  1.1148 -	x = dstrect->x;
  1.1149 -	y = dstrect->y;
  1.1150 -	width = dstrect->w;
  1.1151 -	height = dstrect->h;
  1.1152 +    float x, y, width, height;
  1.1153 +    float u0, v0, u1, v1;
  1.1154 +    unsigned char alpha;
  1.1155 +    float centerx, centery;
  1.1156  
  1.1157 -	u0 = srcrect->x;
  1.1158 -	v0 = srcrect->y;
  1.1159 -	u1 = srcrect->x + srcrect->w;
  1.1160 -	v1 = srcrect->y + srcrect->h;
  1.1161 -	
  1.1162 +    x = dstrect->x;
  1.1163 +    y = dstrect->y;
  1.1164 +    width = dstrect->w;
  1.1165 +    height = dstrect->h;
  1.1166 +
  1.1167 +    u0 = srcrect->x;
  1.1168 +    v0 = srcrect->y;
  1.1169 +    u1 = srcrect->x + srcrect->w;
  1.1170 +    v1 = srcrect->y + srcrect->h;
  1.1171 +
  1.1172      centerx = center->x;
  1.1173      centery = center->y;
  1.1174 -		
  1.1175 -	alpha = texture->a;
  1.1176 -	
  1.1177 -	StartDrawing(renderer);
  1.1178 -	TextureActivate(texture);
  1.1179 -	PSP_SetBlendMode(renderer, renderer->blendMode);
  1.1180 -	
  1.1181 -	if(alpha != 255)
  1.1182 -	{
  1.1183 -		sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
  1.1184 -		sceGuColor(GU_RGBA(255, 255, 255, alpha));
  1.1185 -	}else{
  1.1186 -		sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
  1.1187 -		sceGuColor(0xFFFFFFFF);
  1.1188 -	}
  1.1189 +
  1.1190 +    alpha = texture->a;
  1.1191 +
  1.1192 +    StartDrawing(renderer);
  1.1193 +    TextureActivate(texture);
  1.1194 +    PSP_SetBlendMode(renderer, renderer->blendMode);
  1.1195 +
  1.1196 +    if(alpha != 255)
  1.1197 +    {
  1.1198 +        sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
  1.1199 +        sceGuColor(GU_RGBA(255, 255, 255, alpha));
  1.1200 +    }else{
  1.1201 +        sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
  1.1202 +        sceGuColor(0xFFFFFFFF);
  1.1203 +    }
  1.1204  
  1.1205 -//		x += width * 0.5f;
  1.1206 -//		y += height * 0.5f;
  1.1207 -	x += centerx;
  1.1208 -	y += centery;		
  1.1209 -	
  1.1210 -	float c, s;
  1.1211 -	
  1.1212 -	MathSincos(degToRad(angle), &s, &c);
  1.1213 -	
  1.1214 -//		width *= 0.5f;
  1.1215 -//		height *= 0.5f;
  1.1216 -	width  -= centerx;
  1.1217 -	height -= centery;		
  1.1218 -	
  1.1219 -	
  1.1220 -	float cw = c*width;
  1.1221 -	float sw = s*width;
  1.1222 -	float ch = c*height;
  1.1223 -	float sh = s*height;
  1.1224 +//      x += width * 0.5f;
  1.1225 +//      y += height * 0.5f;
  1.1226 +    x += centerx;
  1.1227 +    y += centery;
  1.1228 +
  1.1229 +    float c, s;
  1.1230 +
  1.1231 +    MathSincos(degToRad(angle), &s, &c);
  1.1232  
  1.1233 -	VertTV* vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2);
  1.1234 +//      width *= 0.5f;
  1.1235 +//      height *= 0.5f;
  1.1236 +    width  -= centerx;
  1.1237 +    height -= centery;
  1.1238 +
  1.1239 +
  1.1240 +    float cw = c*width;
  1.1241 +    float sw = s*width;
  1.1242 +    float ch = c*height;
  1.1243 +    float sh = s*height;
  1.1244 +
  1.1245 +    VertTV* vertices = (VertTV*)sceGuGetMemory(sizeof(VertTV)<<2);
  1.1246  
  1.1247 -	vertices[0].u = u0;
  1.1248 -	vertices[0].v = v0;
  1.1249 -	vertices[0].x = x - cw + sh;
  1.1250 -	vertices[0].y = y - sw - ch;
  1.1251 -	vertices[0].z = 0;
  1.1252 -			
  1.1253 -	vertices[1].u = u0;
  1.1254 -	vertices[1].v = v1;
  1.1255 -	vertices[1].x = x - cw - sh;
  1.1256 -	vertices[1].y = y - sw + ch;
  1.1257 -	vertices[1].z = 0;
  1.1258 -	
  1.1259 -	vertices[2].u = u1;
  1.1260 -	vertices[2].v = v1;
  1.1261 -	vertices[2].x = x + cw - sh;
  1.1262 -	vertices[2].y = y + sw + ch;
  1.1263 -	vertices[2].z = 0;
  1.1264 -	
  1.1265 -	vertices[3].u = u1;
  1.1266 -	vertices[3].v = v0;
  1.1267 -	vertices[3].x = x + cw + sh;
  1.1268 -	vertices[3].y = y + sw - ch;
  1.1269 -	vertices[3].z = 0;
  1.1270 -	
  1.1271 -	if (flip & SDL_FLIP_HORIZONTAL) {
  1.1272 -				Swap(&vertices[0].v, &vertices[2].v);
  1.1273 -				Swap(&vertices[1].v, &vertices[3].v);
  1.1274 -	}
  1.1275 -	if (flip & SDL_FLIP_VERTICAL) {
  1.1276 -				Swap(&vertices[0].u, &vertices[2].u);
  1.1277 -				Swap(&vertices[1].u, &vertices[3].u);
  1.1278 -	}  	
  1.1279 +    vertices[0].u = u0;
  1.1280 +    vertices[0].v = v0;
  1.1281 +    vertices[0].x = x - cw + sh;
  1.1282 +    vertices[0].y = y - sw - ch;
  1.1283 +    vertices[0].z = 0;
  1.1284 +
  1.1285 +    vertices[1].u = u0;
  1.1286 +    vertices[1].v = v1;
  1.1287 +    vertices[1].x = x - cw - sh;
  1.1288 +    vertices[1].y = y - sw + ch;
  1.1289 +    vertices[1].z = 0;
  1.1290 +
  1.1291 +    vertices[2].u = u1;
  1.1292 +    vertices[2].v = v1;
  1.1293 +    vertices[2].x = x + cw - sh;
  1.1294 +    vertices[2].y = y + sw + ch;
  1.1295 +    vertices[2].z = 0;
  1.1296  
  1.1297 -	sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices);
  1.1298 -			
  1.1299 -	if(alpha != 255)
  1.1300 -		sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
  1.1301 +    vertices[3].u = u1;
  1.1302 +    vertices[3].v = v0;
  1.1303 +    vertices[3].x = x + cw + sh;
  1.1304 +    vertices[3].y = y + sw - ch;
  1.1305 +    vertices[3].z = 0;
  1.1306 +
  1.1307 +    if (flip & SDL_FLIP_HORIZONTAL) {
  1.1308 +                Swap(&vertices[0].v, &vertices[2].v);
  1.1309 +                Swap(&vertices[1].v, &vertices[3].v);
  1.1310 +    }
  1.1311 +    if (flip & SDL_FLIP_VERTICAL) {
  1.1312 +                Swap(&vertices[0].u, &vertices[2].u);
  1.1313 +                Swap(&vertices[1].u, &vertices[3].u);
  1.1314 +    }
  1.1315 +
  1.1316 +    sceGuDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D, 4, 0, vertices);
  1.1317 +
  1.1318 +    if(alpha != 255)
  1.1319 +        sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
  1.1320      return 0;
  1.1321  }
  1.1322  
  1.1323 @@ -961,39 +961,39 @@
  1.1324  PSP_RenderPresent(SDL_Renderer * renderer)
  1.1325  {
  1.1326      PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
  1.1327 -	if(!data->displayListAvail)
  1.1328 -		return;
  1.1329 -	
  1.1330 -	data->displayListAvail = SDL_FALSE;
  1.1331 -	sceGuFinish();
  1.1332 -	sceGuSync(0,0);
  1.1333 -	
  1.1334 -//	if(data->vsync)
  1.1335 -		sceDisplayWaitVblankStart();
  1.1336 -			
  1.1337 +    if(!data->displayListAvail)
  1.1338 +        return;
  1.1339 +
  1.1340 +    data->displayListAvail = SDL_FALSE;
  1.1341 +    sceGuFinish();
  1.1342 +    sceGuSync(0,0);
  1.1343 +
  1.1344 +//  if(data->vsync)
  1.1345 +        sceDisplayWaitVblankStart();
  1.1346 +
  1.1347      data->backbuffer = data->frontbuffer;
  1.1348      data->frontbuffer = vabsptr(sceGuSwapBuffers());
  1.1349 -		
  1.1350 +
  1.1351  }
  1.1352  
  1.1353  static void
  1.1354  PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  1.1355  {
  1.1356 -	PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
  1.1357 -	PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
  1.1358 -	
  1.1359 -	if (renderdata == 0)
  1.1360 -		return;
  1.1361 +    PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
  1.1362 +    PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
  1.1363 +
  1.1364 +    if (renderdata == 0)
  1.1365 +        return;
  1.1366  
  1.1367 -	if(psp_texture == 0)
  1.1368 -		return;
  1.1369 +    if(psp_texture == 0)
  1.1370 +        return;
  1.1371  
  1.1372 -	if(psp_texture->data != 0)
  1.1373 -	{
  1.1374 -		SDL_free(psp_texture->data);
  1.1375 -	}
  1.1376 -	SDL_free(psp_texture);
  1.1377 -	texture->driverdata = NULL;
  1.1378 +    if(psp_texture->data != 0)
  1.1379 +    {
  1.1380 +        SDL_free(psp_texture->data);
  1.1381 +    }
  1.1382 +    SDL_free(psp_texture);
  1.1383 +    texture->driverdata = NULL;
  1.1384  }
  1.1385  
  1.1386  static void
  1.1387 @@ -1001,17 +1001,17 @@
  1.1388  {
  1.1389      PSP_RenderData *data = (PSP_RenderData *) renderer->driverdata;
  1.1390      if (data) {
  1.1391 -		if (!data->initialized)
  1.1392 -			return;
  1.1393 +        if (!data->initialized)
  1.1394 +            return;
  1.1395 +
  1.1396 +        StartDrawing(renderer);
  1.1397  
  1.1398 -		StartDrawing(renderer);
  1.1399 -		
  1.1400 -		sceGuTerm();
  1.1401 -//		vfree(data->backbuffer);
  1.1402 -//		vfree(data->frontbuffer);
  1.1403 -		
  1.1404 -		data->initialized = SDL_FALSE;
  1.1405 -		data->displayListAvail = SDL_FALSE;
  1.1406 +        sceGuTerm();
  1.1407 +//      vfree(data->backbuffer);
  1.1408 +//      vfree(data->frontbuffer);
  1.1409 +
  1.1410 +        data->initialized = SDL_FALSE;
  1.1411 +        data->displayListAvail = SDL_FALSE;
  1.1412          SDL_free(data);
  1.1413      }
  1.1414      SDL_free(renderer);