#include <tscope.h>
#define REALEXP
#define NWORDS 10
char word[NWORDS][20];
char nonword[NWORDS][20];
void readstim()
{
FILE *fp;
fp = fopen("words.txt", "r");
if (fp == NULL)
ts_fatal("error opening words.txt");
int i;
for (i = 0; i < NWORDS; i++)
fscanf(fp, "%s", word[i]);
fclose(fp);
fp = fopen("nonwords.txt", "r");
if (fp == NULL)
ts_fatal("error opening nonwords.txt");
for (i = 0; i < NWORDS; i++)
fscanf(fp, "%s", nonword[i]);
fclose(fp);
}
#ifdef TESTSTIM
int main()
{
readstim();
int i;
for (i = 0; i < NWORDS; i++)
printf("%s %s\n", word[i], nonword[i]);
return 0;
}
END_OF_MAIN();
#endif
#define WN 2
#define NSTIM NWORDS
#define NTRIALS (WN*NSTIM)
struct {
int subj;
int rmap;
int wn;
int stimnr;
char stim[20];
int xr;
int r;
int corr;
int rt;
int re;
} data[NTRIALS];
#define TESTLIST FALSE
void randomize(int subjnr)
{
int i, tmp[NTRIALS];
if (TESTLIST) {
for (i = 0; i < NTRIALS; i++)
tmp[i] = i;
} else
ts_rlist(NTRIALS, 1, tmp);
for (i = 0; i < NTRIALS; i++) {
data[i].subj = subjnr;
data[i].rmap = subjnr % 2;
data[i].wn = tmp[i] % WN;
data[i].stimnr = tmp[i] / WN;
if (data[i].wn == 1)
sprintf(data[i].stim, "%s", word[data[i].stimnr]);
else
sprintf(data[i].stim, "%s", nonword[data[i].stimnr]);
if (data[i].rmap == 0) {
if (data[i].wn == 0)
data[i].xr = 2;
else
data[i].xr = 1;
} else {
if (data[i].wn == 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].wn);
fprintf(outfile, "%d ", data[i].stimnr);
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, "%s ", data[i].stim);
fprintf(outfile, "\n");
}
fclose(outfile);
}
#ifdef TESTRND
int main()
{
readstim();
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);
ts_printf_centre(0, 0, "%s", data[i].stim);
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);
readstim();
randomize(subjnr);
ts_clrscr();
if (data[0].rmap == 0) {
ts_printf_centre(0, 10,
"press the left mouse button if you see a word");
ts_printf_centre(0, 0,
"press the right mouse button if you see a nonword");
} else {
ts_printf_centre(0, 10,
"press the right mouse button if you see a word");
ts_printf_centre(0, 0,
"press the left mouse button if you see a nonword");
}
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