I'm trying to bring back PSMS 1.2 (Sega Master System Emulator for PS2) to life again by converting it to GsKit and using some ideas/code I got from FCEUltra for PS2 by ragnarok2040.
It's already loading ROMs from every device (MC/USB/MASS/HDD...) and it's running at full speed with sound. However, as I'm a newbie with all this GsKit/PS2 stuff, I'm facing problems with the PS2 CLUT. This is leading me to a screen like this:
instead of this:
As you guys can see, colors are all messed up. I have tried a couple of things but with no success. Here are some fragments of pertinent code (you can download full sources and a working binary at the end of this post as well):
bitmap and clut data variables:
Code: Select all
u8 bitmap_data[256 * 256] __attribute__((aligned(128))) __attribute__ ((section (".bss"))); // SMS display is only 256x192, extra data is padding
u16 clut[256] __attribute__((aligned(16))) __attribute__ ((section (".bss")));
Code: Select all
void setupSMSTexture(void) {
SMSTEX.PSM = GS_PSM_T8;
SMSTEX.ClutPSM = GS_PSM_CT16;
SMSTEX.Clut = (u32 *)clut;
SMSTEX.VramClut = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(16, 16, SMSTEX.ClutPSM), GSKIT_ALLOC_USERBUFFER);
SMSTEX.Width = 256;
SMSTEX.Height = 256;
SMSTEX.TBW = 4; //256;
SMSTEX.Vram = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(SMSTEX.Width, SMSTEX.Height, SMSTEX.PSM), GSKIT_ALLOC_USERBUFFER);
}
Code: Select all
void update_video()
{
SMSTEX.Mem = (u32 *)bitmap_data;
gsKit_texture_upload(gsGlobal, &SMSTEX);
/* vsync and flip buffer */
gsKit_sync_flip(gsGlobal);
/* execute render queue */
gsKit_queue_exec(gsGlobal);
}
Code: Select all
void palette_sync(int index)
{
int r, g, b;
if(IS_GG)
{
r = ((vdp.cram[(index << 1) | 0] >> 1) & 7) << 5;
g = ((vdp.cram[(index << 1) | 0] >> 5) & 7) << 5;
b = ((vdp.cram[(index << 1) | 1] >> 1) & 7) << 5;
}
else
{
r = ((vdp.cram[index] >> 0) & 3) << 6;
g = ((vdp.cram[index] >> 2) & 3) << 6;
b = ((vdp.cram[index] >> 4) & 3) << 6;
}
bitmap.pal.color[index][0] = r;
bitmap.pal.color[index][1] = g;
bitmap.pal.color[index][2] = b;
pixel[index] = MAKE_PIXEL(r, g, b);
bitmap.pal.dirty[index] = bitmap.pal.update = 1;
clut[index] = ( ((b>>3)<<10) | ((g>>3)<<5) | (g>>3) );
//clut[index | 0x20] = ( ((b>>3)<<10) | ((g>>3)<<5) | (r>>3) );
//clut[index | 0x40] = ( ((b>>3)<<10) | ((g>>3)<<5) | (r>>3) );
}
Hope you guys can help me on this issue, so we can have another great emulator for the PS2 homebrew library! ;)
Thanks!
bootsector