#include <tscope.h>
#include <tscope/oldscope.h>
#define ECCENT 100
#define NBLOCKS 2
#define NTRIALS 20
#define ALLTRIALS NBLOCKS * NTRIALS
#define TFIX mtt(1500)
#define TCUE mtt(50)
#define MAXTARGET mtt(1000)
#define MAXRESPONSE mtt(2000)
#define ENDO 1
map *fixpunt, *target, *vierkant_dun, *vierkant_dik, *fix, *cue_l, *cue_r,
*arrow_r, *target_l, *target_r;
int stimlijst[NTRIALS] = { 1, 1, 1, 1, 2, 2, 2, 2, 3, 4,
1, 1, 1, 1, 2, 2, 2, 2, 3, 4
};
int soalijst[NTRIALS] = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
200, 200, 200, 200, 200, 200, 200, 200, 200, 200
};
struct {
int rt, err;
int stim;
int resp;
int soa;
int acc;
} data[ALLTRIALS];
struct {
__int64 junk;
__int64 t1, e1;
__int64 t2, e2;
__int64 t3, e3;
} tmp;
void PrepareStuff()
{
int a;
fixpunt = ts_makebmp(40, 40);
target = ts_makebmp(20, 20);
vierkant_dun = ts_makebmp(60, 60);
vierkant_dik = ts_makebmp(60, 60);
arrow_r = ts_makebmp(20, 10);
ts_tobmp(fixpunt);
ts_fill(1);
ts_circle(0, 0, 5);
ts_fill(0);
ts_tobmp(target);
ts_fill(1);
ts_rect(-20, -20, 20, 20);
ts_fill(0);
ts_tobmp(vierkant_dun);
ts_rect(-25, -25, 25, 25);
ts_tobmp(vierkant_dik);
ts_rect(-25, -25, 25, 25);
ts_rect(-28, -28, 28, 28);
ts_rect(-29, -29, 29, 29);
ts_tobmp(arrow_r);
ts_fill(1);
ts_rect(-9, -1, 9, 1);
ts_line(10, 0, 3, -8);
ts_line(9, 0, 2, -8);
ts_line(10, 0, 3, 8);
ts_line(9, 0, 2, 8);
ts_fill(0);
fix = ts_makebmp(400, 60);
cue_l = ts_makebmp(400, 60);
cue_r = ts_makebmp(400, 60);
target_l = ts_makebmp(400, 60);
target_r = ts_makebmp(400, 60);
ts_tobmp(fix);
ts_blit(fixpunt, 0, 0);
ts_blit(vierkant_dun, -ECCENT, 0);
ts_blit(vierkant_dun, ECCENT, 0);
if (ENDO) {
ts_tobmp(cue_l);
ts_blit(fixpunt, 0, 0);
ts_flipblit(arrow_r, HFLIP, 0, -20);
ts_blit(vierkant_dun, -ECCENT, 0);
ts_blit(vierkant_dun, ECCENT, 0);
ts_tobmp(cue_r);
ts_blit(fixpunt, 0, 0);
ts_blit(arrow_r, 0, -20);
ts_blit(vierkant_dun, -ECCENT, 0);
ts_blit(vierkant_dun, ECCENT, 0);
}
else {
ts_tobmp(cue_l);
ts_blit(fixpunt, 0, 0);
ts_blit(vierkant_dik, -ECCENT, 0);
ts_blit(vierkant_dun, ECCENT, 0);
ts_tobmp(cue_r);
ts_blit(fixpunt, 0, 0);
ts_blit(vierkant_dun, -ECCENT, 0);
ts_blit(vierkant_dik, ECCENT, 0);
}
ts_tobmp(target_l);
ts_blit(fixpunt, 0, 0);
ts_blit(vierkant_dun, -ECCENT, 0);
ts_blit(vierkant_dun, ECCENT, 0);
ts_blit(target, -ECCENT, 0);
ts_tobmp(target_r);
ts_blit(fixpunt, 0, 0);
ts_blit(vierkant_dun, -ECCENT, 0);
ts_blit(vierkant_dun, ECCENT, 0);
ts_blit(target, ECCENT, 0);
ts_toscr();
ts_defkey(KEY_Z);
ts_defkey(KEY_M);
ts_defkey(KEY_ESC);
for (a = 0; a < ALLTRIALS; a++) {
data[a].rt = 0;
data[a].err = 0;
data[a].resp = 0;
data[a].stim = 0;
}
}
void DestroyStims()
{
ts_killbmp(fix);
ts_killbmp(cue_l);
ts_killbmp(cue_r);
ts_killbmp(target_l);
ts_killbmp(target_r);
ts_killbmp(fixpunt);
ts_killbmp(target);
ts_killbmp(vierkant_dun);
ts_killbmp(vierkant_dik);
ts_killbmp(arrow_r);
}
void trial(int trialnr)
{
ts_vsync(&tmp.junk, &tmp.junk);
ts_blit(fix, 0, 0);
ts_wait(TFIX);
if (data[trialnr].stim == 1 || data[trialnr].stim == 4) {
ts_vsync(&tmp.t1, &tmp.e1);
ts_blit(cue_l, 0, 0);
ts_wait(TCUE);
}
if (data[trialnr].stim == 2 || data[trialnr].stim == 3) {
ts_vsync(&tmp.t1, &tmp.e1);
ts_blit(cue_r, 0, 0);
ts_wait(TCUE);
}
ts_vsync(&tmp.junk, &tmp.junk);
ts_blit(fix, 0, 0);
ts_wait(mtt(data[trialnr].soa));
if (data[trialnr].stim == 1 || data[trialnr].stim == 3) {
ts_vsync(&tmp.t2, &tmp.e2);
ts_blit(target_l, 0, 0);
}
if (data[trialnr].stim == 2 || data[trialnr].stim == 4) {
ts_vsync(&tmp.t2, &tmp.e2);
ts_blit(target_r, 0, 0);
}
data[trialnr].resp = ts_resp(&tmp.t3, &tmp.e3, MAXTARGET);
ts_blit(fix, 0, 0);
if (!data[trialnr].resp)
data[trialnr].resp = ts_resp(&tmp.t3, &tmp.e3, MAXRESPONSE);
if (data[trialnr].resp == 3)
exit(0);
data[trialnr].rt = ttm(tmp.t3 - tmp.t2);
data[trialnr].err = ttmu(tmp.e2 + tmp.e3);
}
void Block(int blocknr)
{
int a;
int c, list[NTRIALS];
ts_rlist(NTRIALS, 1, list);
for (c = 0; c < NTRIALS; c++) {
data[blocknr * NTRIALS + c].stim = stimlijst[list[c]];
data[blocknr * NTRIALS + c].soa = soalijst[list[c]];
}
for (a = 0; a < NTRIALS; a++) {
trial(blocknr * NTRIALS + a);
}
}
void Feedback()
{
int a;
int v_rt_correct = 0, i_rt_correct = 0, v_rt_wrong = 0, i_rt_wrong =
0, v_n_correct = 0, i_n_correct = 0, v_n_wrong = 0, i_n_wrong = 0;
float v_mrt = 0, i_mrt = 0;
float v_pe = 0, i_pe = 0;
for (a = 0; a < ALLTRIALS; a++) {
if (data[a].stim == 1) {
if (data[a].resp == 1) {
v_rt_correct += data[a].rt;
v_n_correct++;
data[a].acc = 1;
} else {
v_rt_wrong += data[a].rt;
v_n_wrong++;
data[a].acc = 0;
}
}
if (data[a].stim == 2) {
if (data[a].resp == 2) {
v_rt_correct += data[a].rt;
v_n_correct++;
data[a].acc = 1;
} else {
v_rt_wrong += data[a].rt;
v_n_wrong++;
data[a].acc = 0;
}
}
if (data[a].stim == 3) {
if (data[a].resp == 1) {
i_rt_correct += data[a].rt;
i_n_correct++;
data[a].acc = 1;
} else {
i_rt_wrong += data[a].rt;
i_n_wrong++;
data[a].acc = 0;
}
}
if (data[a].stim == 4) {
if (data[a].resp == 2) {
i_rt_correct += data[a].rt;
i_n_correct++;
data[a].acc = 1;
} else {
i_rt_wrong += data[a].rt;
i_n_wrong++;
data[a].acc = 0;
}
}
}
v_mrt = v_rt_correct / v_n_correct;
i_mrt = i_rt_correct / i_n_correct;
v_pe =
((float) (v_n_wrong) /
((float) (v_n_correct) + (float) (v_n_wrong))) * 100;
i_pe =
((float) (i_n_wrong) /
((float) (i_n_correct) + (float) (i_n_wrong))) * 100;
ts_fgcolor(GREEN);
ts_clrscr();
ts_printf_centre(0, 0, "mean reaction times");
ts_printf_centre(0, -10, "-------------------");
ts_printf_centre(0, -30,
"Valid cues (#%d) : %5.0lf ms (%.0lf%% err.)",
v_n_correct + v_n_wrong, v_mrt, v_pe);
ts_printf_centre(0, -40,
"Invalid cues (#%d): %5.0lf ms (%.0lf%% err.)",
i_n_correct + i_n_wrong, i_mrt, i_pe);
ts_fgcolor(WHITE);
ts_button(XMAX - 20, -YMAX + 20);
}
void Instructions()
{
ts_tobuff();
ts_blit(fix, 0, 100);
ts_blit(cue_l, 0, 0);
ts_blit(target_l, 0, -100);
ts_fgcolor(GREEN);
ts_printf_centre(0, YMAX - 40, "Valid cue left");
ts_printf_right(-200, 100, "fixation");
ts_printf_right(-200, 0, "cue");
ts_printf_right(-200, -100, "target");
ts_printf_right(-200, -YMAX + 40, "Response:");
ts_printf_centre(0, -YMAX + 40, "at target onset, press 'z'");
ts_fgcolor(WHITE);
ts_blitbuff();
ts_clrbuff();
ts_button(XMAX - 20, -YMAX + 20);
ts_blit(fix, 0, 100);
ts_blit(cue_r, 0, 0);
ts_blit(target_r, 0, -100);
ts_fgcolor(GREEN);
ts_printf_centre(0, YMAX - 40, "Valid cue right");
ts_printf_right(-200, 100, "fixation");
ts_printf_right(-200, 0, "cue");
ts_printf_right(-200, -100, "target");
ts_printf_right(-200, -YMAX + 40, "Response:");
ts_printf_centre(0, -YMAX + 40, "at target onset, press 'm'");
ts_fgcolor(WHITE);
ts_blitbuff();
ts_clrbuff();
ts_button(XMAX - 20, -YMAX + 20);
ts_blit(fix, 0, 100);
ts_blit(cue_l, 0, 0);
ts_blit(target_r, 0, -100);
ts_fgcolor(GREEN);
ts_printf_centre(0, YMAX - 40, "Invalid cue left");
ts_printf_right(-200, 100, "fixation");
ts_printf_right(-200, 0, "cue");
ts_printf_right(-200, -100, "target");
ts_printf_right(-200, -YMAX + 40, "Response:");
ts_printf_centre(0, -YMAX + 40, "at target onset, press 'm'");
ts_fgcolor(WHITE);
ts_blitbuff();
ts_clrbuff();
ts_button(XMAX - 20, -YMAX + 20);
ts_blit(fix, 0, 100);
ts_blit(cue_r, 0, 0);
ts_blit(target_l, 0, -100);
ts_fgcolor(GREEN);
ts_printf_centre(0, YMAX - 40, "Invalid cue right");
ts_printf_right(-200, 100, "fixation");
ts_printf_right(-200, 0, "cue");
ts_printf_right(-200, -100, "target");
ts_printf_right(-200, -YMAX + 40, "Response:");
ts_printf_centre(0, -YMAX + 40, "at target onset, press 'z'");
ts_fgcolor(WHITE);
ts_blitbuff();
ts_clrbuff();
ts_button(XMAX - 20, -YMAX + 20);
ts_clrscr();
ts_printf_centre(0, 0, "Get Ready!");
ts_blitbuff();
ts_button(XMAX - 20, -YMAX + 20);
ts_clrscr();
ts_toscr();
}
int main()
{
int a;
ts_scrsize(SIZE3);
ts_scrmode(FULLSCREEN_ACCEL);
ts_doublebuff(TRUE);
ts_init();
PrepareStuff();
Instructions();
ts_priority(HIGH);
for (a = 0; a < NBLOCKS; a++) {
Block(a);
}
ts_priority(NORMAL);
Feedback();
DestroyStims();
return 0;
}
END_OF_MAIN();