/*
            __
           / /_______________  ____  ___
          / __/ ___/ ___/ __ \/ __ \/ _ \
         / /_(__  ) /__/ /_/ / /_/ /  __/
         \__/____/\___/\____/ .___/\___/
                           /_/
  
   michael stevens
   
   test graphics modes
   
    1. test whether the graphics parameters in "tscope.cfg" are supported by your system
        - if the graphics mode is not supported the program closes with an error message
        - if some of the parameters are automatically adjusted they appear in red 
        - an in-depth description of the automatic parameter 
          changes can be found in the reference manual
    2. test whether the timing/vsync parameters in "tscope.cfg" are supported by your system
        - if some of the parameters are automatically adjusted they appear in red 
    3. short test of vsync performance (10 cycles)
    4. long test of vsync performance (10000 cycles)
   
*/

#include <tscope.h>
#include <tscope/internal.h>

// read & test screen parameters ----------------------------------------------
void screensetup()
{
    ts_scrcfg("tscope.cfg");
    ts_init();
    int i, x, y;

    // refreshrate
    y = 20;
    x = ts_printf(20, y, "refreshrate: %d -> ", _refreshrate);
    if (_actual_refreshrate != _refreshrate)
        ts_fgcolor(RED);
    ts_printf(20 + x, y, "%d", _actual_refreshrate);
    ts_fgcolor(WHITE);

    // colordepth
    y = 40;
    x = ts_printf(20, y, "colordepth: %d -> ", _screendepth);
    if (_screendepth != _actualdepth)
        ts_fgcolor(RED);
    ts_printf(20 + x, y, "%d", _actualdepth);
    ts_fgcolor(WHITE);

    // screensize
    for (i = 0; i < _nscreensize; i++)
        if (_screensize == _vscreensize[i])
            break;
    y = 60;
    ts_printf(20, y, "screensize: (%s/%s)", _sscreensize[i],
              _sscreensize[i + _nscreensize / 2]);
    y = 80;
    x = ts_printf(20, y, "            %dx%d -> ", _screenx, _screeny);

    if (_screenx != _actualx || _screeny != _actualy)
        ts_fgcolor(RED);
    ts_printf(20 + x, y, "%dx%d", _actualx, _actualy);
    ts_fgcolor(WHITE);

    // screenmode
    for (i = 0; i < _nscreenmode; i++)
        if (_screenmode == _vscreenmode[i])
            break;
    y = 100;
    ts_printf(20, y, "screenmode: %s", _sscreenmode[i]);

    // wait for a click
    ts_button(ax(.5), ay(.75));
    ts_clrscr();
}

// read & test timing parameters ----------------------------------------------
void timersetup()
{
    ts_timercfg("tscope.cfg");
    int i, x, y;

    // priority
    for (i = 0; i < _npriority; i++)
        if (_priority == _vpriority[i])
            break;
    y = 20;
    ts_printf(20, y, "priority: %s", _spriority[i]);

    // waitmode
    for (i = 0; i < _nwaitmode; i++)
        if (_wait_flag == _vwaitmode[i])
            break;
    y = 40;
    ts_printf(20, y, "wait mode: %s", _swaitmode[i]);

    // vsyncmode
    for (i = 0; i < _nvsyncmode; i++)
        if (_vsync_flag == _vvsyncmode[i])
            break;
    y = 60;
    x = ts_printf(20, y, "vsync mode: ");
    if (_vsync_requestedmode != WHATEVER
        && _vsync_requestedmode != _vsync_flag)
        ts_fgcolor(RED);
    ts_printf(20 + x, y, "%s", _svsyncmode[i]);
    ts_fgcolor(WHITE);


    // vsync limit
    y = 80;
    ts_printf(20, y, "vsync limit: %d ", _vsync_limit);

    // wait for a click
    ts_button(ax(.5), ay(.75));
    ts_clrscr();
}

// short vsync test -----------------------------------------------------------
void synctest1()
{
    ts_printf(20, 20, "short test of vsync performance");
    ts_printf(20, 30, "(test 10 refresh cycles)");
    ts_printf(20, 40, "vsync interval should be about %d u.",
              ttmu(_vsyncinterval));

    int i;
    int y = 60;
    __int64 prev_t, curr_t, junk;
    ts_wait(mtt(500));
    for (i = 0; i < 10; i++) {
        ts_wait(_vsyncinterval / 2);
        ts_vsync(&curr_t, &junk);
        if (i > 0) {
            y += 10;
            if (curr_t - prev_t >= _vsyncinterval + mtt(1))
                ts_fgcolor(RED);
            ts_printf(20, y, "vsync: %2d. interval: %d u.", i + 1,
                      ttmu(curr_t - prev_t));
            ts_fgcolor(WHITE);
        }
        prev_t = curr_t;
    }
    ts_wait(mtt(500));
    ts_button(ax(.5), ay(.75));
    ts_clrscr();
}

// long vsync test ------------------------------------------------------------
void synctest2()
{

    ts_printf(20, 20, "long test of vsync performance");
    ts_printf(20, 30, "(test 10000 refresh cycles)");
    ts_printf(20, 40, "every screen cycle a pixel is drawn");
    ts_printf(20, 50, "missed syncs will appear in red");

    ts_wait(mtt(500));
    int miss = 0;
    int i, x, y;
    __int64 prev_t, curr_t, junk;
    ts_rect(SCREEN_W / 2 - 51, SCREEN_H / 2 - 51, SCREEN_W / 2 + 50,
            SCREEN_H / 2 + 50);
    ts_vsync(&prev_t, &junk);
    for (i = 0; i < 10000; i++) {
        ts_wait(_vsyncinterval / 2);
        ts_vsync(&curr_t, &junk);
        x = SCREEN_W / 2 - 50 + i % 100;
        y = SCREEN_H / 2 - 50 + i / 100;
        if (curr_t - prev_t >= _vsyncinterval + mtt(1)) {
            ts_fgcolor(RED);
            miss++;
        }
        ts_putpixel(x, y);
        ts_fgcolor(WHITE);
        prev_t = curr_t;
    }


    ts_wait(mtt(500));
    ts_printf(20, SCREEN_H - 40, "%d out of 10000 vsyncs were missed",
              miss);
    ts_button(ax(.5), ay(.75));
    ts_clrscr();
}


// main entry point -----------------------------------------------------------
int main()
{
    ts_debug(DEBUG0);
    ts_coordinates(STANDARD);
    screensetup();
    timersetup();
    synctest1();
    synctest2();
    return 0;
}

END_OF_MAIN();


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information