RetroArch/psp1/psp1_video.c

196 lines
4.3 KiB
C
Raw Normal View History

/* 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
*
* 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>
#include "../psp/sdk_defines.h"
#include "../general.h"
#include "../driver.h"
#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
typedef struct psp1_video
{
bool rgb32;
unsigned tex_w;
unsigned tex_h;
} psp1_video_t;
static unsigned int __attribute__((aligned(16))) list[262144];
static void init_texture(void *data, const video_info_t *video)
{
2014-02-11 13:10:47 +00:00
psp1_video_t *psp = (psp1_video_t*)data;
2012-11-23 06:19:21 +00:00
sceGuInit();
sceGuStart(GU_DIRECT, list);
2014-02-11 13:10:47 +00:00
sceGuDrawBuffer(psp->rgb32 ? GU_PSM_8888 : GU_PSM_5650, (void*)0, SCEGU_VRAM_WIDTH);
sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, (void*)0x88000, SCEGU_VRAM_WIDTH);
sceGuClear(GU_COLOR_BUFFER_BIT);
sceGuOffset(2048 - (SCEGU_SCR_WIDTH / 2), 2048 - (SCEGU_SCR_HEIGHT / 2));
sceGuViewport(2048, 2048, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
2014-02-11 13:10:47 +00:00
sceGuTexMode(psp->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);
sceGuTexFilter(GU_LINEAR, GU_LINEAR);
sceGuEnable(GU_TEXTURE_2D);
sceGuFrontFace(GU_CW);
sceGuDisable(GU_BLEND);
sceGuFinish();
sceGuSync(0, 0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
2014-02-11 13:10:47 +00:00
psp->rgb32 = video->rgb32;
}
2012-11-26 23:50:29 +00:00
static void *psp_init(const video_info_t *video,
const input_driver_t **input, void **input_data)
{
*input = NULL;
*input_data = NULL;
(void)video;
if (driver.video_data)
{
2014-02-11 13:10:47 +00:00
psp1_video_t *psp = (psp1_video_t*)driver.video_data;
/* Reinitialize textures here */
//init_texture(vid, video);
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));
2014-02-11 13:10:47 +00:00
if (!psp)
goto error;
2014-02-11 13:10:47 +00:00
init_texture(psp, video);
2014-02-11 13:10:47 +00:00
psp->tex_w = 512;
psp->tex_h = 512;
2014-02-11 13:10:47 +00:00
return psp;
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,
unsigned width, unsigned height, unsigned pitch, const char *msg)
{
(void)width;
(void)height;
(void)pitch;
(void)msg;
2014-02-11 13:10:47 +00:00
psp1_video_t *psp = (psp1_video_t*)data;
if(!frame)
return true;
sceKernelDcacheWritebackInvalidateAll();
sceGuStart(GU_DIRECT, list);
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGuClearColor(GU_COLOR(0.0f,0.0f,0.0f,1.0f));
sceGuClearDepth(0);
2014-02-12 18:27:03 +00:00
sceGuCopyImage(psp->rgb32 ?GU_PSM_8888:GU_PSM_5650,0,0,width,height,pitch/2,frame,0,0,512,(void*)0x44088000);
sceGuFinish();
sceDisplayWaitVblankStart();
void *frame_ptr = &frame;
return true;
}
2012-11-26 23:50:29 +00:00
static void psp_set_nonblock_state(void *data, bool toggle)
{
(void)data;
(void)toggle;
}
2012-11-26 23:50:29 +00:00
static bool psp_alive(void *data)
{
(void)data;
return true;
}
2012-11-26 23:50:29 +00:00
static bool psp_focus(void *data)
{
(void)data;
return true;
}
2012-11-26 23:50:29 +00:00
static void psp_free(void *data)
{
(void)data;
sceGuTerm();
}
#ifdef RARCH_CONSOLE
2012-11-26 23:50:29 +00:00
static void psp_restart(void) {}
#endif
2012-11-26 23:50:29 +00:00
static void psp_set_rotation(void *data, unsigned rotation)
{
}
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,
NULL,
2012-11-26 23:50:29 +00:00
psp_free,
"psp1",
2014-02-11 15:10:40 +00:00
#if defined(HAVE_MENU)
2012-11-26 23:50:29 +00:00
psp_restart,
#endif
2012-11-26 23:50:29 +00:00
psp_set_rotation,
};