#include <tscope.h>
#define REALEXP
#define COLOR 2
#define POSITION 2
#define CELLS (COLOR*POSITION)
#define REP 3
#define NTRIALS (CELLS*REP)
struct {
int subj;
int rmap;
int color;
int position;
int xr;
int r;
int corr;
int rt;
int re;
} data[NTRIALS];
#define TESTLIST TRUE
void randomize(int subjnr)
{
int i, tmp[NTRIALS];
if (TESTLIST) {
for (i = 0; i < NTRIALS; i++)
tmp[i] = i % CELLS;
} else
ts_rlist(CELLS, REP, tmp);
for (i = 0; i < NTRIALS; i++) {
data[i].subj = subjnr;
data[i].rmap = subjnr % 2;
data[i].color = tmp[i] % COLOR;
data[i].position = tmp[i] / COLOR;
if (data[i].rmap == 0) {
if (data[i].color == 0)
data[i].xr = 2;
else
data[i].xr = 1;
} else {
if (data[i].color == 0)
data[i].xr = 1;
else
data[i].xr = 2;
}
data[i].r = 0;
data[i].corr = 0;
data[i].rt = 0;
data[i].re = 0;
}
}
void writedata()
{
char filename[20];
sprintf(filename, "data%d.rtd", data[0].subj);
FILE *outfile;
outfile = fopen(filename, "a+");
if (outfile == NULL)
ts_fatal("error opening output file");
int i;
for (i = 0; i < NTRIALS; i++) {
fprintf(outfile, "%d ", data[i].subj);
fprintf(outfile, "%d ", data[i].rmap);
fprintf(outfile, "%d ", data[i].color);
fprintf(outfile, "%d ", data[i].position);
fprintf(outfile, "%d ", data[i].xr);
fprintf(outfile, "%d ", data[i].r);
fprintf(outfile, "%d ", data[i].corr);
fprintf(outfile, "%4d ", data[i].rt);
fprintf(outfile, "%4d ", data[i].re);
fprintf(outfile, "\n");
}
fclose(outfile);
}
#ifdef TESTRND
int main()
{
int i;
for (i = 0; i < 4; i++) {
randomize(i);
writedata();
}
return 0;
}
END_OF_MAIN();
#endif
#define FIXTM 500
#define BLANKTM 500
#define MAXTM 1500
#define FBTM 200
#define ITI 1500
struct {
__int64 junk;
__int64 t1, e1;
__int64 t2, e2;
} tmp;
void trial(int i)
{
ts_vsync(&tmp.junk, &tmp.junk);
ts_printf_centre(0, 0, "+");
ts_wait(mtt(FIXTM));
ts_vsync(&tmp.junk, &tmp.junk);
ts_clrscr();
ts_vsync(&tmp.t1, &tmp.e1);
if (data[i].color == 0)
ts_fgcolor(RED);
else
ts_fgcolor(GREEN);
ts_fill(ON);
if (data[i].position == 0)
ts_circle(-ax(.5), 0, 20);
else
ts_circle(ax(.5), 0, 20);
ts_fill(OFF);
ts_fgcolor(WHITE);
data[i].r = ts_resp(&tmp.t2, &tmp.e2, mtt(MAXTM));
ts_clrscr();
data[i].rt = ttm(tmp.t2 - tmp.t1);
data[i].re = ttmu(tmp.e2 + tmp.e1);
if (data[i].r == 3)
ts_fatal("aborted by user");
if (data[i].r == data[i].xr)
data[i].corr = 1;
else
data[i].corr = 0;
if (!data[i].corr)
ts_playstream(mtt(FBTM));
ts_wait(mtt(ITI));
}
#define TRIALTEST TRUE
#ifdef REALEXP
int main()
{
if (!TRIALTEST) {
ts_scrsize(SIZE3);
ts_scrmode(FULLSCREEN);
} else
ts_scrsize(SIZE1);
ts_init();
ts_defkey(M1);
ts_defkey(M2);
ts_defkey(KEY_ESC);
int subjnr;
do {
ts_clrscr();
int y = ts_printf(-XMAX + 20, YMAX - 20, "Participant number: ");
ts_scanf(-XMAX + 20 + y, YMAX - 20, "%d", &subjnr);
} while (subjnr < 0 || subjnr > 20);
randomize(subjnr);
ts_clrscr();
if (data[0].rmap == 0) {
ts_printf_centre(0, 10,
"press the left mouse button if you see a red circle");
ts_printf_centre(0, 0,
"press the right mouse button if you see a green circle");
} else {
ts_printf_centre(0, 10,
"press the right mouse button if you see a green circle");
ts_printf_centre(0, 0,
"press the left mouse button if you see a red circle");
}
ts_printf_centre(0, -10, "press escape to stop");
ts_button(XMAX - 20, -YMAX + 20);
ts_clrscr();
ts_wait(mtt(1000));
int i;
for (i = 0; i < NTRIALS; i++)
trial(i);
writedata();
ts_printf_centre(0, 0, "all done, thanks!");
ts_button(XMAX - 20, -YMAX + 20);
return 0;
}
END_OF_MAIN();
#endif