#include <tscope.h>
#include <tscope/internal.h>
void screensetup()
{
ts_scrcfg("tscope.cfg");
ts_init();
int i, x, y;
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);
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);
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);
for (i = 0; i < _nscreenmode; i++)
if (_screenmode == _vscreenmode[i])
break;
y = 100;
ts_printf(20, y, "screenmode: %s", _sscreenmode[i]);
ts_button(ax(.5), ay(.75));
ts_clrscr();
}
void timersetup()
{
ts_timercfg("tscope.cfg");
int i, x, y;
for (i = 0; i < _npriority; i++)
if (_priority == _vpriority[i])
break;
y = 20;
ts_printf(20, y, "priority: %s", _spriority[i]);
for (i = 0; i < _nwaitmode; i++)
if (_wait_flag == _vwaitmode[i])
break;
y = 40;
ts_printf(20, y, "wait mode: %s", _swaitmode[i]);
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);
y = 80;
ts_printf(20, y, "vsync limit: %d ", _vsync_limit);
ts_button(ax(.5), ay(.75));
ts_clrscr();
}
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();
}
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();
}
int main()
{
ts_debug(DEBUG0);
ts_coordinates(STANDARD);
screensetup();
timersetup();
synctest1();
synctest2();
return 0;
}
END_OF_MAIN();