Force PAL using SDL

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Force PAL using SDL

Post by kouky »

I have 2 playstation 2 slim (a black and a pink one) they both PAL, but on the pink one, my homebrew using SDL make the console to switch ot NTSC signal...

How can I force the console to stay in PAL mode?
This is how I initialize the SDL:

Code: Select all

	/* Initialize SDL */
	if &#40; SDL_Init&#40;SDL_INIT_VIDEO|SDL_INIT_JOYSTICK&#41; < 0 &#41; &#123;
		fprintf&#40;stderr, "Couldn't initialize SDL&#58; %s\n",SDL_GetError&#40;&#41;&#41;;
		exit&#40;1&#41;;
	&#125;
	atexit&#40;SDL_Quit&#41;;

	videoflags = SDL_SWSURFACE;
	while&#40; argc > 1 &#41; &#123;
		--argc;
		if &#40; argv&#91;argc&#93; && !strcmp&#40;argv&#91;argc&#93;, "-fullscreen"&#41; &#41; &#123;
			videoflags |= SDL_FULLSCREEN;
		&#125; else &#123;
			fprintf&#40;stderr, "Usage&#58; %s &#91;-fullscreen&#93;\n", argv&#91;0&#93;&#41;;
			exit&#40;1&#41;;
		&#125;
	&#125;

     /* Initialize the screen / window */
      screenS = SDL_SetVideoMode&#40;640, 480, 16, videoflags&#41;;
X
softwares for artists on video game systems - http://www.pikilipita.com
dlanor
Posts: 258
Joined: Thu Oct 28, 2004 6:28 pm
Location: Stockholm, Sweden

Re: Force PAL using SDL

Post by dlanor »

kouky wrote:I have 2 playstation 2 slim (a black and a pink one) they both PAL, but on the pink one, my homebrew using SDL make the console to switch ot NTSC signal...
That is probably because the SDL libs use the same incorrect way of testing for video region as used by the old gsKit versions (as in: if(gsKit_detect_signal()==GS_MODE_PAL)). I think ragnarok2040 fixed that in his new gsKit updates, though I haven't checked it myself.

That old test method will work correctly only for the old fat PS2 consoles, but will cause all (I think) slim models to be misinterpreted as NTSC even for a PAL region.

This caused old versions of uLaunchELF to start with incorrect video mode on such consoles. But in recent versions of uLE this has been fixed by making a definitely correct test for the video region, by reading the "rom0:ROMVER" file from the bios rom of the console. The fifth character of that file indicates the video region in the same way as in some region dependent folder names, such that:

'E' == Europe == PAL
'U' == USA == NTSC/U
'I' == Japan == NTSC/J
How can I force the console to stay in PAL mode?
This is how I initialize the SDL:
For SDL I'm not sure how best to work around it, but the definite fix should be to correct the bug inside the SDL implementation, thus eliminating the need for SDL-using applications to fix it on their own.

Best regards: dlanor
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

Thanks for your lights. Unfortunately you don't seem to have a solution for me :(

I believe cosmito fixed that issue in the SDL Doom port:
I also added the option to force a specific display mode (PAL or NTSC) for whom needs it - So just rename the DOOM.ELF to something ending with PAL or NTSC at the name (for example : DOOM_PAL.ELF or DOOM_NTSC.ELF).
But I can't find the sources of his port and he didn't explained how he fixed it...
softwares for artists on video game systems - http://www.pikilipita.com
ragnarok2040
Posts: 202
Joined: Wed Aug 09, 2006 1:00 am

Post by ragnarok2040 »

It looks like he uses a static int called force_signal. Setting it to 0 forces PAL and setting it to 1 forces it to NTSC.

To fix the problem in SDL itself, for use with older revisions of gsKit, the autodetection code needs changed to do what dlanor specified.

In sdl/src/video/ps2sdk/SDL_ps2video.c:

Code: Select all

        pal = &#40;REG_VIDEO_MODE == MODE_PAL&#41;;
        if &#40;force_signal != -1&#41;
        &#123;
                /* 0 PAL, 1 NTSC */
                pal = &#40;force_signal == 0&#41;;
        &#125;

        printf&#40;"SDL&#58; initializing gsKit in %s mode\n", pal ? "PAL" &#58; "NTSC"&#41;;
        gsGlobal = gsKit_init_global&#40;pal ? GS_MODE_PAL &#58; GS_MODE_NTSC&#41;;
needs to be changed to something like:

Code: Select all

        int fd;
        char romname&#91;14&#93;;
        fd = fioOpen&#40;"rom0&#58;ROMVER", O_RDONLY&#41;;
        fioRead&#40;fd, &romname, 14&#41;;
        fioClose&#40;fd&#41;;

        printf&#40;"SDL&#58; initializing gsKit in %s mode\n", &#40;romname&#91;4&#93; == 'E'&#41; ? "PAL" &#58; "NTSC"&#41;;
        gsGlobal = gsKit_init_global&#40;&#40;romname&#91;4&#93; == 'E'&#41; ? GS_MODE_PAL &#58; GS_MODE_NTSC&#41;;
You'll need to add this to the top to avoid warnings about implicit declarations:

Code: Select all

#include <fileio.h>
To work with the newest version of gsKit, as dlanor suspected, all that region checking code wouldn't be needed as just calling gsKit_init_global() would setup an autodetected mode using the same method as above. Unfortunately, I'm not sure what else in SDL would need changing. From the looks of it, I don't think anything else is needed, but that's just my opinion from a cursory glance. For most apps that used the default interlaced field mode, it's usually just that call, since gsKit_init_global() doesn't take a mode parameter anymore.

A quick explanation of custom video modes using the newest revision of gsKit(in case you want to implement any in SDL itself):
  • Any display mode can be used by defining:
    • gsGlobal->Mode
      gsGlobal->Interlace
      gsGlobal->Field
      gsGlobal->Width
      gsGlobal->Height
    The Mode option takes any mode defined in gsInit.h.
    The Interlace option takes GS_SETTING_ON for interlaced or GS_SETTING_OFF for non-interlaced.
    Setting Interlace off halves the useable height.
    The Field option takes GS_FRAME or GS_FIELD, where GS_FIELD uses full height and GS_FRAME uses half the height.
    The Field option has no effect when Interlace is off.
    The Width/Height dimensions are factors of the greatest common multiple(GCM) of the chosen display mode's width/height.
    Calling gsKit_init_screen() after defining all of those fields will change the mode.

    For example:
    • GS_MODE_DTV_1080I has a max screen resolution of 1920x1080.
      This means the GCM for width is 1920 and GCM for height is 1080.
      That means draw buffer dimensions can be:
      • 640x540
        960x540
        1920x540
        640x1080
        960x1080
        1920x1080
      Smaller dimensions are probably possible.
      Keep in mind that the larger dimensions won't leave enough vram for any normal usage.
    Another example:
    • GS_MODE_NTSC and GS_MODE_PAL use a GCM of 2560 for width.
      These are the only modes that use such a large GCM.
      This is to support multiple widths of 256, 320, 384, 512, 640.
      NTSC's GCM for height is 448 and PAL's GCM for height is 512.
      Now you have a choice of at least 10 different combinations from 256x224 to 640x448 in NTSC and 256x256 to 640x512 in PAL.
      Remember that heights of 224 or 256 need to be used for non-interlaced mode or interlaced GS_FRAME mode.
Probably a bit of information overload, but anyone interested in changing the SDL video implementation can use this as a reference.
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

I downloaded the latest version of gskit from the svn.
I compiled and installed the gsKit lib

I downloaded the latest version of SDL from the svn.

on the file sdl/src/video/ps2sdk/SDL_ps2video.c,
I replaced the region checking system code by just:

Code: Select all

gsGlobal = gsKit_init_global&#40;&#41;;
I compiled and installed the SDL lib.

And now my pink slim PS2 is detected as a PAL one, which is correct :)

Thanks a lot Dlanor and Ragnarok2040 for your explanations, they were really helpfull.
softwares for artists on video game systems - http://www.pikilipita.com
cosmito
Posts: 307
Joined: Sun Mar 04, 2007 4:26 am
Location: Portugal
Contact:

Post by cosmito »

kouky wrote:Thanks for your lights. Unfortunately you don't seem to have a solution for me :(

I believe cosmito fixed that issue in the SDL Doom port:
I also added the option to force a specific display mode (PAL or NTSC) for whom needs it - So just rename the DOOM.ELF to something ending with PAL or NTSC at the name (for example : DOOM_PAL.ELF or DOOM_NTSC.ELF).
But I can't find the sources of his port and he didn't explained how he fixed it...
(already typed at the other thread, but for the others that might being reading this :
here's the sources of the two ports i'm experimenting with:

http://svn2.assembla.com/svn/pedroduart ... ldoom_PS2/
http://svn2.assembla.com/svn/pedroduart ... 2doom-src/
Post Reply