2012-11-23 04:20:05 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
2012-11-23 04:20:05 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <pspkernel.h>
|
|
|
|
#include <pspdisplay.h>
|
2012-11-23 06:19:21 +00:00
|
|
|
#include <pspgu.h>
|
|
|
|
#include <pspgum.h>
|
2012-11-23 04:20:05 +00:00
|
|
|
|
|
|
|
#include "../psp/sdk_defines.h"
|
|
|
|
#include "../general.h"
|
|
|
|
#include "../driver.h"
|
|
|
|
|
2012-11-26 20:23:31 +00:00
|
|
|
#ifndef SCEGU_SCR_WIDTH
|
|
|
|
#define SCEGU_SCR_WIDTH 480
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SCEGU_SCR_HEIGHT
|
|
|
|
#define SCEGU_SCR_HEIGHT 272
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SCEGU_VRAM_WIDTH
|
|
|
|
#define SCEGU_VRAM_WIDTH 512
|
|
|
|
#endif
|
2012-11-23 04:20:05 +00:00
|
|
|
|
|
|
|
typedef struct psp1_video
|
|
|
|
{
|
|
|
|
bool rgb32;
|
|
|
|
unsigned tex_w;
|
|
|
|
unsigned tex_h;
|
|
|
|
} psp1_video_t;
|
|
|
|
|
2014-02-16 18:44:00 +00:00
|
|
|
typedef struct psp1_vertex
|
|
|
|
{
|
|
|
|
u16 u,v;
|
|
|
|
u16 color;
|
|
|
|
u16 x,y,z;
|
|
|
|
}psp1_vertex_t;
|
|
|
|
|
|
|
|
|
2012-11-23 04:20:05 +00:00
|
|
|
static unsigned int __attribute__((aligned(16))) list[262144];
|
|
|
|
|
|
|
|
|
2014-02-16 19:52:14 +00:00
|
|
|
|
2014-02-16 20:26:56 +00:00
|
|
|
static void init_texture(void *data, unsigned width, unsigned height, bool rgb32)
|
2012-11-23 04:20:05 +00:00
|
|
|
{
|
2014-02-11 13:10:47 +00:00
|
|
|
psp1_video_t *psp = (psp1_video_t*)data;
|
2014-02-16 18:44:00 +00:00
|
|
|
|
2012-11-23 04:20:05 +00:00
|
|
|
sceGuStart(GU_DIRECT, list);
|
|
|
|
|
2014-02-16 20:26:56 +00:00
|
|
|
sceGuDrawBuffer(rgb32 ? GU_PSM_8888 : GU_PSM_5650, (void*)0, SCEGU_VRAM_WIDTH);
|
|
|
|
sceGuDispBuffer(width, height, (void*)0x88000, SCEGU_VRAM_WIDTH);
|
2014-02-16 18:44:00 +00:00
|
|
|
sceGuClearColor(GU_COLOR(0.0f,0.0f,1.0f,1.0f));
|
2014-02-16 20:26:56 +00:00
|
|
|
sceGuScissor(0, 0, width, height);
|
2012-11-23 04:20:05 +00:00
|
|
|
sceGuEnable(GU_SCISSOR_TEST);
|
2014-02-16 20:26:56 +00:00
|
|
|
sceGuTexMode(rgb32 ? GU_PSM_8888 : GU_PSM_5650, 0, 0, GU_FALSE);
|
2012-11-23 06:19:21 +00:00
|
|
|
sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
|
2014-02-16 18:44:00 +00:00
|
|
|
sceGuTexFilter(GU_LINEAR, GU_LINEAR);
|
|
|
|
sceGuTexWrap ( GU_CLAMP,GU_CLAMP );
|
2012-11-23 04:20:05 +00:00
|
|
|
sceGuEnable(GU_TEXTURE_2D);
|
|
|
|
sceGuDisable(GU_BLEND);
|
2014-02-16 18:44:00 +00:00
|
|
|
sceGuDisable (GU_DEPTH_TEST);
|
2012-11-23 04:20:05 +00:00
|
|
|
sceGuFinish();
|
|
|
|
sceGuSync(0, 0);
|
2014-02-16 18:44:00 +00:00
|
|
|
|
2012-11-23 04:20:05 +00:00
|
|
|
sceDisplayWaitVblankStart();
|
2014-02-16 18:44:00 +00:00
|
|
|
|
2012-11-23 04:20:05 +00:00
|
|
|
sceGuDisplay(GU_TRUE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-26 23:50:29 +00:00
|
|
|
static void *psp_init(const video_info_t *video,
|
2012-11-23 04:20:05 +00:00
|
|
|
const input_driver_t **input, void **input_data)
|
|
|
|
{
|
2014-02-13 07:31:45 +00:00
|
|
|
void *pspinput;
|
2012-11-23 04:20:05 +00:00
|
|
|
(void)video;
|
|
|
|
|
2014-02-13 07:31:45 +00:00
|
|
|
|
2012-11-23 04:20:05 +00:00
|
|
|
if (driver.video_data)
|
|
|
|
{
|
2014-02-11 13:10:47 +00:00
|
|
|
psp1_video_t *psp = (psp1_video_t*)driver.video_data;
|
2012-11-23 04:20:05 +00:00
|
|
|
|
|
|
|
/* Reinitialize textures here */
|
2014-02-16 20:26:56 +00:00
|
|
|
psp->rgb32 = video->rgb32;
|
|
|
|
init_texture(psp, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, psp->rgb32);
|
2012-11-23 04:20:05 +00:00
|
|
|
|
|
|
|
return driver.video_data;
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:10:47 +00:00
|
|
|
psp1_video_t *psp = (psp1_video_t*)calloc(1, sizeof(psp1_video_t));
|
2012-11-23 04:20:05 +00:00
|
|
|
|
2014-02-11 13:10:47 +00:00
|
|
|
if (!psp)
|
2012-11-23 04:20:05 +00:00
|
|
|
goto error;
|
|
|
|
|
2014-02-16 20:26:56 +00:00
|
|
|
sceGuInit();
|
|
|
|
|
2014-02-16 14:24:35 +00:00
|
|
|
if (input && input_data)
|
|
|
|
{
|
|
|
|
pspinput = input_psp.init();
|
|
|
|
*input = pspinput ? &input_psp : NULL;
|
|
|
|
*input_data = pspinput;
|
|
|
|
}
|
2014-02-13 07:31:45 +00:00
|
|
|
|
2014-02-16 20:26:56 +00:00
|
|
|
psp->rgb32 = video->rgb32;
|
|
|
|
init_texture(psp, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, psp->rgb32);
|
2012-11-23 04:20:05 +00:00
|
|
|
|
2014-02-11 13:10:47 +00:00
|
|
|
psp->tex_w = 512;
|
|
|
|
psp->tex_h = 512;
|
2012-11-23 04:20:05 +00:00
|
|
|
|
2014-02-11 13:10:47 +00:00
|
|
|
return psp;
|
2012-11-23 04:20:05 +00:00
|
|
|
error:
|
|
|
|
RARCH_ERR("PSP1 video could not be initialized.\n");
|
|
|
|
return (void*)-1;
|
|
|
|
}
|
|
|
|
|
2012-11-26 23:50:29 +00:00
|
|
|
static bool psp_frame(void *data, const void *frame,
|
2012-11-23 04:20:05 +00:00
|
|
|
unsigned width, unsigned height, unsigned pitch, const char *msg)
|
|
|
|
{
|
|
|
|
(void)width;
|
|
|
|
(void)height;
|
|
|
|
(void)pitch;
|
|
|
|
(void)msg;
|
2014-02-16 19:52:14 +00:00
|
|
|
int x,y;
|
2014-02-16 18:44:00 +00:00
|
|
|
|
2014-02-11 13:10:47 +00:00
|
|
|
psp1_video_t *psp = (psp1_video_t*)data;
|
2014-02-16 19:52:14 +00:00
|
|
|
|
2012-11-23 04:20:05 +00:00
|
|
|
|
|
|
|
if(!frame)
|
|
|
|
return true;
|
2014-02-16 19:52:14 +00:00
|
|
|
|
|
|
|
void* g_texture = (void*) (0x44110000); // video memory after draw+display buffers
|
|
|
|
if (psp->rgb32){
|
|
|
|
pitch/=4;
|
|
|
|
u32* out_p=(u32*)g_texture ;
|
|
|
|
u32* in_p=(u32*)frame;
|
|
|
|
for ( y=0;y<height;y++ ){
|
|
|
|
for ( x=0;x<width;x++ ){
|
|
|
|
*out_p=((*in_p)&0xFF00FF00)|(((*in_p)&0xFF)<<16)|(((*in_p)&0xFF0000)>>16);
|
|
|
|
in_p++;
|
|
|
|
out_p++;
|
|
|
|
}
|
|
|
|
in_p+=pitch-width;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
pitch/=2;
|
|
|
|
u16* out_p=(u16*)g_texture;
|
|
|
|
u16* in_p=(u16*)frame;
|
|
|
|
for ( y=0;y<height;y++ ){
|
|
|
|
for ( x=0;x<width;x++ ){
|
|
|
|
*out_p=((*in_p)&0x7E0)|(((*in_p)&0x1F)<<11)|((*in_p)>>11);
|
|
|
|
in_p++;
|
|
|
|
out_p++;
|
|
|
|
}
|
|
|
|
in_p+=pitch-width;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-23 04:20:05 +00:00
|
|
|
sceGuStart(GU_DIRECT, list);
|
2014-02-16 18:44:00 +00:00
|
|
|
sceGuClear(GU_COLOR_BUFFER_BIT);
|
|
|
|
psp1_vertex_t* v = sceGuGetMemory(2*sizeof(psp1_vertex_t));
|
|
|
|
|
|
|
|
v[0].x=(SCEGU_SCR_WIDTH-width*SCEGU_SCR_HEIGHT/height)/2;
|
|
|
|
v[0].y=0;
|
2014-02-16 19:52:14 +00:00
|
|
|
v[0].u=0;
|
2014-02-16 18:44:00 +00:00
|
|
|
v[0].v=0;
|
|
|
|
|
|
|
|
v[1].x=(SCEGU_SCR_WIDTH+width*SCEGU_SCR_HEIGHT/height)/2;
|
|
|
|
v[1].y=(SCEGU_SCR_HEIGHT);
|
2014-02-16 19:52:14 +00:00
|
|
|
v[1].u=width;
|
2014-02-16 18:44:00 +00:00
|
|
|
v[1].v=height;
|
|
|
|
|
2014-02-16 19:52:14 +00:00
|
|
|
sceGuTexImage(0,256,256,width,g_texture);
|
2014-02-16 18:44:00 +00:00
|
|
|
|
|
|
|
sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_5650|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,NULL,v);
|
2012-11-23 04:20:05 +00:00
|
|
|
sceGuFinish();
|
2014-02-16 18:44:00 +00:00
|
|
|
sceGuSync(0,0);
|
2012-11-23 04:20:05 +00:00
|
|
|
sceDisplayWaitVblankStart();
|
2014-02-16 18:44:00 +00:00
|
|
|
sceGuSwapBuffers();
|
2012-11-23 04:20:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-26 23:50:29 +00:00
|
|
|
static void psp_set_nonblock_state(void *data, bool toggle)
|
2012-11-23 04:20:05 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
(void)toggle;
|
|
|
|
}
|
|
|
|
|
2012-11-26 23:50:29 +00:00
|
|
|
static bool psp_alive(void *data)
|
2012-11-23 04:20:05 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-26 23:50:29 +00:00
|
|
|
static bool psp_focus(void *data)
|
2012-11-23 04:20:05 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-26 23:50:29 +00:00
|
|
|
static void psp_free(void *data)
|
2012-11-23 04:20:05 +00:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
sceGuTerm();
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:12:06 +00:00
|
|
|
#ifdef HAVE_MENU
|
2012-11-26 23:50:29 +00:00
|
|
|
static void psp_restart(void) {}
|
2012-11-23 04:20:05 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-26 23:50:29 +00:00
|
|
|
static void psp_set_rotation(void *data, unsigned rotation)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-11-23 04:20:05 +00:00
|
|
|
const video_driver_t video_psp1 = {
|
2012-11-26 23:50:29 +00:00
|
|
|
psp_init,
|
|
|
|
psp_frame,
|
|
|
|
psp_set_nonblock_state,
|
|
|
|
psp_alive,
|
|
|
|
psp_focus,
|
2012-11-23 04:20:05 +00:00
|
|
|
NULL,
|
2012-11-26 23:50:29 +00:00
|
|
|
psp_free,
|
2012-11-23 04:20:05 +00:00
|
|
|
"psp1",
|
|
|
|
|
2014-02-11 15:10:40 +00:00
|
|
|
#if defined(HAVE_MENU)
|
2012-11-26 23:50:29 +00:00
|
|
|
psp_restart,
|
2012-11-23 04:20:05 +00:00
|
|
|
#endif
|
2012-11-26 23:50:29 +00:00
|
|
|
|
|
|
|
psp_set_rotation,
|
2012-11-23 04:20:05 +00:00
|
|
|
};
|
|
|
|
|