forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PSMS Reloaded v0.1 - Problems with GsKit/CLUT

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
bootsector_



Joined: 25 Feb 2008
Posts: 15

PostPosted: Mon Feb 25, 2008 1:26 am    Post subject: PSMS Reloaded v0.1 - Problems with GsKit/CLUT Reply with quote

Hi folks!

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:
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")));


Setting up SMS screen texture:
Code:
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);
}


Update video function:
Code:
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);
}


Palette building routine (this is called with indexes between 0 and 31):
Code:
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) );
}


If you need to see the real thing, you can download a working binary here and full source code here.

Hope you guys can help me on this issue, so we can have another great emulator for the PS2 homebrew library! ;)

Thanks!

bootsector
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Mon Feb 25, 2008 2:15 am    Post subject: Reply with quote

Your issue is that the CLUT colors on the PS2 are not stored in order from 0 to 31, instead you should store it in this order (first 32 values, indices in HEX)

Code:

00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17
08 | 09 | 0A | 0B | 0C | 0D | 0E | 0F | 18 | 19 | 1A | 1B | 1C | 1D | 1E | 1F
...


See the GS Manual section "CLUT Storage Mode" for more details.

Nice job bringing the emulator code up to date :-)
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
bootsector_



Joined: 25 Feb 2008
Posts: 15

PostPosted: Mon Feb 25, 2008 3:33 am    Post subject: Reply with quote

You're right, Lukasz! I noted that ragnarok2040 did this on FCEUltra. I actually tried to do this in PSMS, but by the wrong way! Now I fixed the palette_sync function and it's now generating a valid CLUT! Thanks for your support!

Best regards,

bootsector
Back to top
View user's profile Send private message
cosmito



Joined: 04 Mar 2007
Posts: 314
Location: Portugal

PostPosted: Mon Feb 25, 2008 4:35 am    Post subject: Reply with quote

Thanks bootsector_ for keeping the PS2 scene alive in these days. I recommend you a free SVN repository service (www.assembla.com) for keeping your sources. This way, you'll have a free repository for you files and for us an always up-to-date version.
Back to top
View user's profile Send private message Visit poster's website
bootsector_



Joined: 25 Feb 2008
Posts: 15

PostPosted: Mon Feb 25, 2008 8:59 am    Post subject: Reply with quote

Hi folks,

First public/playable version was just released:

http://psx-scene.com/forums/ps2-homebrew-dev-emu-scene/65070-psms-reloaded.html
Back to top
View user's profile Send private message
Wraggster



Joined: 26 Aug 2005
Posts: 121

PostPosted: Wed Feb 27, 2008 1:46 am    Post subject: Reply with quote

thanks for the news/release, great to see the PS2 get some more loving these days :)
_________________
Webmaster of http://www.dcemu.co.uk

DCEMU The Worlds Only Homebrew & Gaming Network of Sites.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group