Code: Select all
#include <pspgu.h>
#define DEBUG 0
#include "debug.h"
// Basilisk display configuration
#define BII_SCREEN_WIDTH 320
#define BII_SCREEN_HEIGHT 240
int Temp;
static uint32 PspFrameBuffer[BII_SCREEN_WIDTH * BII_SCREEN_HEIGHT];
/// Things from LUAPlayer's graphics.c
//#define SCREEN_WIDTH 480
//#define SCREEN_HEIGHT 272
//#define PSP_LINE_SIZE 512
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define PSP_LINE_SIZE 512
#define FRAMEBUFFER_SIZE (PSP_LINE_SIZE*SCREEN_HEIGHT*2)
u16* g_vram_base = (u16*) (0x40000000 | 0x04000000);
typedef struct
{
unsigned short u, v;
unsigned short color;
short x, y, z;
} Vertex;
static unsigned int __attribute__((aligned(16))) list[256];
static int dispBufferNumber;
typedef u16 Color;
Color* getVramDrawBuffer()
{
Color* vram = (Color*) g_vram_base;
if (dispBufferNumber == 0) vram += FRAMEBUFFER_SIZE / 2;
return vram;
}
/// Things from LUAPlayer's graphics.c
/*
* Initialization
*/
bool VideoInit(bool classic)
{
// Buffer
// PspFrameBuffer = (uint32 *)malloc(BII_SCREEN_WIDTH * BII_SCREEN_HEIGHT * 4);
// guInit - Taken from initGraphics() in graphics.c from LUAPlayer
sceDisplaySetMode(0, SCREEN_WIDTH, SCREEN_HEIGHT);
dispBufferNumber = 0;
sceDisplayWaitVblankStart();
sceDisplaySetFrameBuf((void*) g_vram_base, PSP_LINE_SIZE, 1, 1);
sceGuInit();
sceGuStart(GU_DIRECT, list);
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*) 0x110000, 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);
sceGuTexMode(GU_PSM_8888, 0, 0, 0);
sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
sceGuTexFilter(GU_NEAREST, GU_NEAREST);
sceGuAmbientColor(0xffffffff);
sceGuFinish();
sceGuSync(0, 0);
sceDisplayWaitVblankStart();
sceGuDisplay(1);
// Configure the Basilisk II framebuffer.
VideoMonitor.x = BII_SCREEN_WIDTH;
VideoMonitor.y = BII_SCREEN_HEIGHT;
VideoMonitor.mode = VMODE_32BIT;
VideoMonitor.bytes_per_row = SCREEN_WIDTH * 4;
VideoMonitor.mac_frame_base = Host2MacAddr((uint8 *)PspFrameBuffer);
// Done.
D(bug("video "));
return true;
}
void video_set_palette(unsigned char *p)
{
D(bug("video_set_palette called\n"));
}
/*
* Deinitialization
*/
void VideoExit(void)
{
// free(PspFrameBuffer);
sceGuTerm();
}
/*
* Video message handling
*/
void VideoInterrupt(void)
{
// blitImageToScreen(...) with some modifications.
Color* vram = getVramDrawBuffer();
sceKernelDcacheWritebackInvalidateAll();
sceGuStart(GU_DIRECT,list);
sceGuCopyImage(GU_PSM_8888, 0, 0, BII_SCREEN_WIDTH, BII_SCREEN_HEIGHT,
SCREEN_WIDTH, PspFrameBuffer, 0, 0, PSP_LINE_SIZE, vram);
sceGuFinish();
sceGuSync(0,0);
// flipScreen()
sceGuSwapBuffers();
sceDisplaySetFrameBuf(vram, PSP_LINE_SIZE, 1, 1);
dispBufferNumber ^= 1;
}