About 50/60 Hz

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 171
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

About 50/60 Hz

Post by Newbie »

Well, i use the pvr functions to set video and display things on the screen.
Reading a post about strange behavior about pal /ntsc mode, suddenly a question knock my head ...

Using PVR default initialization, is the hardware able to detect type of frequency resolution to perform itself ?

If yes, is there any mean to get the selected frequency after initialization ?

If no, how to handle the choice between 50/60 hz ?

Thanks for your help :)
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: About 50/60 Hz

Post by BlueCrab »

KOS initializes the display (by default) to a 60Hz mode. If you want to use a 50Hz mode, then you have to select it yourself with one of the vid_set_mode functions. By default, on init, KOS does a vid_set_mode(DM_640x480, PM_RGB565), which as I mentioned will select either DM_640x480_VGA or DM_640x480_NTSC_IL depending on the cable attached.

There's a few reasons (probably) why the code doesn't try to init a PAL mode by default. First, when the video code was written, there was no code in KOS that would allow it to detect the region (and checking the video cable only tells you if it's a composite/RF, RGB, or VGA connection, not what kind of TV it is hooked up to). Another reason was probably that the developers of KOS have almost all been from the US (where we don't have 50Hz TVs at all).

At this point though, I'd imagine there aren't all that many 50Hz only PAL TVs, so it's kinda silly to add the functionality now and change how the defaults are set up. :wink:

There's no way (built-in to KOS) to easily detect whether you've selected a 50Hz or 60Hz mode after initialization. You could directly probe the video register that controls that easily enough, if you really wanted to. Considering you have to go through extra steps to select a 50Hz mode, it'd probably be better for you to just store the fact that you did so somewhere in your code and just use that.
User avatar
Bouz
DCEmu Junior
DCEmu Junior
Posts: 46
Joined: Mon May 10, 2010 3:42 pm
Location: St. Bauzille de Putois (France)
Has thanked: 0
Been thanked: 0

Re: About 50/60 Hz

Post by Bouz »

That said, I am from France and I have not seen a TV that is not 60Hz capable in the last 25 years.
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 171
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Re: About 50/60 Hz

Post by Newbie »

So, lets imagine someone somewhere in this planet having a 50hz display screen.

This person have a Dreamcast hooked up to this screen.

Suddenly he puts a CD Rom on the Dreamcast, the CD Rom contains an auto boot kos pvr_init_default() compiled code.

What will happen ? the screen will burn ?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: About 50/60 Hz

Post by BlueCrab »

The picture will probably just roll and be unstable, as the TV won't be able to sync.
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 171
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Re: About 50/60 Hz

Post by Newbie »

By default, on init, KOS does a vid_set_mode(DM_640x480, PM_RGB565), which as I mentioned will select either DM_640x480_VGA or DM_640x480_NTSC_IL depending on the cable attached.
Well, i did not see where in pvr_init_defaults() the video mode is set.

Code: Select all


int pvr_init_defaults() {
    pvr_init_params_t params = {
        /* Enable opaque and translucent polygons with size 16 */
        { PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_0 },

        /* Vertex buffer size 512K */
        512 * 1024,

        /* No DMA */
        0,

        /* No FSAA */
        0
    };

    return pvr_init(&params);
}

int pvr_init(pvr_init_params_t *params) {
    /* If we're already initialized, fail */
    if(pvr_state.valid == 1) {
        dbglog(DBG_WARNING, "pvr: pvr_init called twice!\n");
        return -1;
    }

    /* Make sure we got valid parameters */
    assert(params != NULL);

    /* Make sure that a video mode has been initialized */
    assert(vid_mode != NULL);
    assert(vid_mode->width != 0 && vid_mode->height != 0);

    /* Check for compatibility with 3D stuff */
    if((vid_mode->width % 32) != 0) {
        dbglog(DBG_WARNING, "pvr: mode %dx%d isn't usable for 3D (width not multiples of 32)\n",
               vid_mode->width, vid_mode->height);
        return -1;
    }

    /* Clear out video memory */
    vid_empty();

    /* Reset all PVR systems (in case it's still doing something) */
    PVR_SET(PVR_RESET, PVR_RESET_ALL);
    PVR_SET(PVR_RESET, PVR_RESET_NONE);

    /* Start off with a nice empty structure */
    memset((void *)&pvr_state, 0, sizeof(pvr_state));

    // Enable DMA if the user wants that.
    pvr_state.dma_mode = params->dma_enabled;

    // Copy over FSAA setting.
    pvr_state.fsaa = params->fsaa_enabled;

    /* Everything's clear, do the initial buffer pointer setup */
    pvr_allocate_buffers(params);

    // Initialize tile matrices
    pvr_init_tile_matrices();

    // Setup all pipeline targets. Yes, this is redundant. :) I just
    // like to have it explicit.
    pvr_state.ram_target = 0;
    pvr_state.ta_target = 0;
    pvr_state.view_target = 0;

    pvr_state.list_reg_open = -1;

    // Sync all the hardware registers with our pipeline state.
    pvr_sync_view();
    pvr_sync_reg_buffer();

    // Clear out our stats
    pvr_state.vbl_count = 0;
    pvr_state.frame_last_time = 0;
    pvr_state.buf_start_time = 0;
    pvr_state.reg_start_time = 0;
    pvr_state.rnd_start_time = 0;
    pvr_state.frame_last_len = -1;
    pvr_state.buf_last_len = -1;
    pvr_state.reg_last_len = -1;
    pvr_state.rnd_last_len = -1;
    pvr_state.vtx_buf_used = 0;
    pvr_state.vtx_buf_used_max = 0;

    /* If we're on a VGA box, disable vertical smoothing */
    if(vid_mode->cable_type == CT_VGA) {
        dbglog(DBG_KDEBUG, "pvr: disabling vertical scaling for VGA\n");

        if(pvr_state.fsaa)
            PVR_SET(PVR_SCALER_CFG, 0x10400);
        else
            PVR_SET(PVR_SCALER_CFG, 0x400);
    }
    else {
        dbglog(DBG_KDEBUG, "pvr: enabling vertical scaling for non-VGA\n");

        if(pvr_state.fsaa)
            PVR_SET(PVR_SCALER_CFG, 0x10401);
        else
            PVR_SET(PVR_SCALER_CFG, 0x401);
    }

    /* Hook the PVR interrupt events on G2 */
    pvr_state.vbl_handle = vblank_handler_add(pvr_int_handler);
    asic_evt_set_handler(ASIC_EVT_PVR_OPAQUEDONE, pvr_int_handler);
    asic_evt_enable(ASIC_EVT_PVR_OPAQUEDONE, ASIC_IRQ_DEFAULT);
    asic_evt_set_handler(ASIC_EVT_PVR_OPAQUEMODDONE, pvr_int_handler);
    asic_evt_enable(ASIC_EVT_PVR_OPAQUEMODDONE, ASIC_IRQ_DEFAULT);
    asic_evt_set_handler(ASIC_EVT_PVR_TRANSDONE, pvr_int_handler);
    asic_evt_enable(ASIC_EVT_PVR_TRANSDONE, ASIC_IRQ_DEFAULT);
    asic_evt_set_handler(ASIC_EVT_PVR_TRANSMODDONE, pvr_int_handler);
    asic_evt_enable(ASIC_EVT_PVR_TRANSMODDONE, ASIC_IRQ_DEFAULT);
    asic_evt_set_handler(ASIC_EVT_PVR_PTDONE, pvr_int_handler);
    asic_evt_enable(ASIC_EVT_PVR_PTDONE, ASIC_IRQ_DEFAULT);
    asic_evt_set_handler(ASIC_EVT_PVR_RENDERDONE, pvr_int_handler);
    asic_evt_enable(ASIC_EVT_PVR_RENDERDONE, ASIC_IRQ_DEFAULT);

    /* 3d-specific parameters; these are all about rendering and
       nothing to do with setting up the video; some stuff in here
       is still unknown. */
    PVR_SET(PVR_UNK_00A8, 0x15d1c951);      /* M (Unknown magic value) */
    PVR_SET(PVR_UNK_00A0, 0x00000020);      /* M */
    PVR_SET(PVR_FB_CFG_2, 0x00000009);      /* alpha config */
    PVR_SET(PVR_UNK_0110, 0x00093f39);      /* M */
    PVR_SET(PVR_UNK_0098, 0x00800408);      /* M */
    PVR_SET(PVR_TEXTURE_CLIP, 0x00000000);      /* texture clip distance */
    PVR_SET(PVR_SPANSORT_CFG, 0x00000101);      /* M */
    PVR_SET(PVR_FOG_TABLE_COLOR, 0x007f7f7f);   /* Fog table color */
    PVR_SET(PVR_FOG_VERTEX_COLOR, 0x007f7f7f);  /* Fog vertex color */
    PVR_SET(PVR_COLOR_CLAMP_MIN, 0x00000000);   /* color clamp min */
    PVR_SET(PVR_COLOR_CLAMP_MAX, 0xffffffff);   /* color clamp max */
    PVR_SET(PVR_UNK_0080, 0x00000007);      /* M */
    PVR_SET(PVR_CHEAP_SHADOW, 0x00000001);      /* cheap shadow */
    PVR_SET(PVR_UNK_007C, 0x0027df77);      /* M */
    PVR_SET(PVR_TEXTURE_MODULO, 0x00000000);    /* stride width */
    PVR_SET(PVR_FOG_DENSITY, 0x0000ff07);       /* fog density */
    PVR_SET(PVR_UNK_00C8, PVR_GET(0x00d4) << 16);   /* M */
    PVR_SET(PVR_UNK_0118, 0x00008040);      /* M */

    /* Initialize PVR DMA */
    mutex_init((mutex_t *)&pvr_state.dma_lock, MUTEX_TYPE_NORMAL);
    pvr_dma_init();

    /* Setup our wait-ready semaphore */
    sem_init((semaphore_t *)&pvr_state.ready_sem, 0);

    /* Set us as valid and return success */
    pvr_state.valid = 1;

    /* Validate our memory pool */
    pvr_mem_reset();
    /* This doesn't work right now... */
    /*#ifndef NDEBUG
        dbglog(DBG_KDEBUG, "pvr: free memory is %08lx bytes\n",
            pvr_mem_available());
    #endif*//* !NDEBUG */

    return 0;
}


User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: About 50/60 Hz

Post by BlueCrab »

It isn't handled there. Video is initialized (and the default mode set) before your main() function is ever called.

It is initialized in the function hardware_periph_init() in the kernel/arch/dreamcast/hardware/hardware.c file. That function is called by the arch_auto_init() function in kernel/arch/dreamcast/kernel/init.c, which is called by the arch_main() function in the same file. That function is called by the assembly code that bootstraps the system (nominally in kernel/arch/dreamcast/kernel/startup.s, but it is actually compiled as part of GCC these days, if you're using a 4.x version).
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 171
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Re: About 50/60 Hz

Post by Newbie »

So there is no way to make something like a selector to choose 50/60hz by user ...
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: About 50/60 Hz

Post by BlueCrab »

It's very easy to make such a thing. Just reinitialize the video to 50Hz mode, display a selector screen, and change it as needed once you're done. I posted a pretty simple example of this over in another thread recently.

Just make sure to only call the function if the user's Dreamcast indicates that it is a European model (since US and Japanese TVs won't handle 50Hz mode at all, most likely). Here's an example of how you might do that:

Code: Select all

#include <dc/flashrom.h>
#include <dc/video.h>

/* This function assumes that the video mode is initialized as KOS
   normally does, that is to 640x480 NTSC IL or 640x480 VGA */
void setup_pal(void) {
    int dc_region, ct;

    dc_region = flashrom_get_region();
    ct = vid_check_cable();

    /* Prompt the user for whether to run in PAL50 or PAL60 if the flashrom says
       the Dreamcast is European and a VGA Box is not hooked up. */ 
    if(dc_region == FLASHROM_REGION_EUROPE && ct != CT_VGA) {
        if(pal_menu() == 1)
            vid_set_mode(DM_640x480_NTSC_IL, PM_RGB565);
        else
            vid_set_mode(DM_640x480_PAL_IL, PM_RGB565);
    }
}
You'll obviously want to do this as early as you can after program startup, since you probably don't want to be displaying anything with the wrong refresh rate.
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 171
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Re: About 50/60 Hz

Post by Newbie »

Ok thanks, i copy paste your code !
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: About 50/60 Hz

Post by BlueCrab »

Newbie wrote:Ok thanks, i copy paste your code !
Cool. Just remember to give credit where credit is due. :wink:
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 171
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Re: About 50/60 Hz

Post by Newbie »

Just to summarize :

1) Dreamcast is american or japan
So only DM_640x480_NTSC_IL

2) Dreamcast hooked with VGA box
So only DM_640x480_NTSC_IL

3) Dreamcast is european and not hooked with VGA box
Choose between DM_640x480_NTSC_IL OR DM_640x480_PAL_IL

is that right ?

And is there any risk to call vid_set_mode() function between two draw ?
I want to be able to change the video mode as the user select in a screen with textures display ...
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: About 50/60 Hz

Post by BlueCrab »

If the Dreamcast is hooked up with a VGA box, the default initialization will set it up for DM_640x480_VGA. Otherwise, the default init is to DM_640x480_NTSC_IL. You shouldn't have to mess with it in either of those situations. If you detect a European console (not on VGA), then change mode to DM_640x480_PAL_IL and display your menu which should allow them to pick between the _NTSC_IL (60hz) and _PAL_IL (50hz) options.

To be honest, I've never tried calling vid_set_mode() without reinitializing the PVR afterwards, but I don't think it should pose any problem as long as you don't change the resolution of the display (since you shouldn't be changing it for VGA, which is the only place it'll matter for the default init).
User avatar
Bouz
DCEmu Junior
DCEmu Junior
Posts: 46
Joined: Mon May 10, 2010 3:42 pm
Location: St. Bauzille de Putois (France)
Has thanked: 0
Been thanked: 0

Re: About 50/60 Hz

Post by Bouz »

Newbie wrote:So, lets imagine someone somewhere in this planet having a 50hz display screen.
I think you are more likely to find a TV that does not support 50Hz display ;-)
User avatar
Newbie
Insane DCEmu
Insane DCEmu
Posts: 171
Joined: Sat Jul 27, 2013 1:16 pm
Has thanked: 0
Been thanked: 0

Re: About 50/60 Hz

Post by Newbie »

1) I have a 50 Hz display PAL monitor, my brother own two of them and i am not the only one :

http://retrorgb.com/rgbmonitors.html

2) changing video mode between two draw calls does not affect display of texture.
Ayla
DC Developer
DC Developer
Posts: 142
Joined: Thu Apr 03, 2008 7:01 am
Has thanked: 0
Been thanked: 4 times
Contact:

Re: About 50/60 Hz

Post by Ayla »

All PAL monitors still accept 50 Hz. But I'm pretty sure that they all accept 60 Hz as well now.
Post Reply