Ok, now it's a texture (as in blit.c) and everything is working, just as fast as before but still it does not seem to be using the CLUT. I will post my code here:
Code: Select all
// Video setup
#define FB_TYPE u16
#define PSP_MODE GU_PSM_5650
#define MAC_MODE FLAYOUT_HOST_565
#define SLICE_SIZE 64
#define PIXEL_SIZE 2
#define SCREEN_WIDTH 480
#define SCREEN_HEIGHT 272
#define PSP_LINE_SIZE 512
#define BII_SCR_WIDTH 480
#define BII_SCR_HEIGHT 272
#define MAC_COLOR_MODE VMODE_16BIT
#define PSP_COLOR_MODE PSP_DISPLAY_PIXEL_FORMAT_565
#define PSP_COLOR_MODE2 GU_COLOR_5650
#define FRAMEBUFFER_SIZE (PSP_LINE_SIZE * SCREEN_HEIGHT * PIXEL_SIZE)
FB_TYPE *g_vram_base = (FB_TYPE *)(0x40000000 | 0x04000000);
static unsigned int __attribute__((aligned(16))) list[256];
static int dispBufferNumber;
inline FB_TYPE *getVramDrawBuffer()
{
return ((!dispBufferNumber) ? g_vram_base + (FRAMEBUFFER_SIZE >> 1) : g_vram_base);
}
struct Vertex
{
unsigned short u, v;
unsigned short color;
short x, y, z;
};
// Basilisk display configuration
static FB_TYPE __attribute__((aligned(16))) PspCLUT[65536];
static FB_TYPE __attribute__((aligned(16))) PspFrameBuffer[PSP_LINE_SIZE * SCREEN_HEIGHT];
/*
* Initialization
*/
bool VideoInit(bool classic)
{
#if !DEBUG
// Build color lookup table
for (int i = 0; i < 65536; i++)
PspCLUT[i] = (i & 0x07e0) | ((i & 0xf800) >> 11) | ((i & 0x001f) << 11);
sceGuInit();
// setup
sceGuStart(GU_DIRECT, list);
sceGuDrawBuffer(PSP_MODE, (void*)0, PSP_LINE_SIZE);
sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, (void*)0x88000, PSP_LINE_SIZE);
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);
sceGuFrontFace(GU_CW);
sceGuEnable(GU_TEXTURE_2D);
sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
sceGuClutMode(PSP_MODE, 0, 0, 0);
sceGuClutLoad(8192, (void *)&PspCLUT);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(1);
#endif
// Configure the Basilisk II framebuffer.
VideoMonitor.x = BII_SCR_WIDTH;
VideoMonitor.y = BII_SCR_HEIGHT;
VideoMonitor.mode = MAC_COLOR_MODE;
VideoMonitor.bytes_per_row = PSP_LINE_SIZE * PIXEL_SIZE;
VideoMonitor.mac_frame_base = MacFrameBaseMac;
MacFrameSize = VideoMonitor.bytes_per_row * VideoMonitor.y;
MacFrameLayout = MAC_MODE;
MacFrameBaseHost = (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)
{
#if !DEBUG
sceGuTerm();
#endif
}
/*
* Video message handling
*/
void VideoInterrupt(void)
{
unsigned int j;
struct Vertex* vertices;
sceGuStart(GU_DIRECT,list);
sceGuTexMode(PSP_MODE, 0, 0, 0);
sceGuTexImage(0, PSP_LINE_SIZE, PSP_LINE_SIZE, PSP_LINE_SIZE, PspFrameBuffer);
sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
sceGuTexFilter(GU_NEAREST, GU_NEAREST);
sceGuTexScale(1.0f / ((float)PSP_LINE_SIZE), 1.0f / ((float)PSP_LINE_SIZE));
sceGuTexOffset(0.0f, 0.0f);
sceGuAmbientColor(0xffffffff);
sceGuClutMode(PSP_MODE, 0, 0, 0);
// do a striped blit (takes the page-cache into account)
for (j = 0; j < BII_SCR_WIDTH; j = j + SLICE_SIZE)
{
vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
vertices[0].u = j; vertices[0].v = 0;
vertices[0].color = 0;
vertices[0].x = j; vertices[0].y = 0; vertices[0].z = 0;
vertices[1].u = j + SLICE_SIZE; vertices[1].v = BII_SCR_HEIGHT;
vertices[1].color = 0;
vertices[1].x = j + SLICE_SIZE; vertices[1].y = BII_SCR_HEIGHT; vertices[1].z = 0;
sceGuDrawArray(GU_SPRITES,
GU_TEXTURE_16BIT | PSP_COLOR_MODE2 | GU_VERTEX_16BIT | GU_TRANSFORM_2D,
2, 0, vertices);
}
sceGuFinish();
sceGuSync(0,0);
sceGuSwapBuffers();
}
Hopefully I am just forgetting something ignorant. Also you will see some extra defines, I tried to double up the video size and have the texture automatically scale down but it just resulted in a black screen (mostly due to a lack of understanding on my part, there are a lot of moving parts in this code).