return 0;
}
-static int import_raw(FILE *f, uint8_t *out[2], int out_byte_count[2],
+static int import_raw(FILE *f, uint8_t **out, int *out_byte_count,
FILE *logf)
{
int count = 0;
char *p;
int i;
- out_byte_count[0] = out_byte_count[1] = 0;
+ *out_byte_count = 0;
while ((p = fgets(buf, sizeof(buf), f)) != NULL)
{
if (count >= alloc) {
alloc = alloc * 2 + 64;
- out[0] = realloc(out[0], alloc * sizeof(out[0][0]));
- if (out[0] == NULL) {
+ *out = realloc(*out, alloc * sizeof((*out)[0]));
+ if (*out == NULL) {
fprintf(stderr, "OOM?\n");
return -1;
}
if (logf)
fwrite(&val, 1, 1, logf);
- out[0][count++] = val & 0x3f;
+ (*out)[count++] = val & 0x3f;
continue;
bad:
}
printf("loaded raw, %d bytes\n", count);
- out_byte_count[0] = count;
+ *out_byte_count = count;
return 0;
}
int pending_urbs = 0;
fd_set rfds, wfds;
const char *tasfn = NULL;
+ const char *tasfn_p2 = NULL;
const char *outfn = NULL;
const char *logfn = NULL;
uint8_t *tas_data[2] = { NULL, NULL };
int tas_data_size[2] = { 0, 0 };
int bytes_sent[2] = { 0, 0 };
int use_vsync = 0; // frame increment on vsync
+ int separate_2p = 0;
int no_start_seq = 0;
int enable_sent = 0;
int abort_sent = 0;
missing_arg(i);
tasfn = argv[i];
continue;
+ case '2':
+ i++;
+ if (argv[i] == NULL)
+ missing_arg(i);
+ tasfn_p2 = argv[i];
+ continue;
case 'w':
i++;
if (argv[i] == NULL)
}
if (tasfn != NULL) {
+ FILE *f, *f_p2 = NULL;
const char *ext;
long size;
- FILE *f;
f = fopen(tasfn, "rb");
if (f == NULL) {
return 1;
}
+ if (tasfn_p2 != NULL) {
+ f_p2 = fopen(tasfn_p2, "rb");
+ if (f_p2 == NULL) {
+ fprintf(stderr, "fopen %s: ", tasfn_p2);
+ perror("");
+ return 1;
+ }
+ }
+
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);
else if (strcasecmp(ext, "bkm") == 0)
ret = import_bkm(f, tas_data, tas_data_size, logf);
else if (strcasecmp(ext, "txt") == 0)
- ret = import_raw(f, tas_data, tas_data_size, logf);
+ ret = import_raw(f, &tas_data[0], &tas_data_size[0], logf);
else {
fprintf(stderr, "unknown movie type: '%s'\n", ext);
return 1;
}
fclose(f);
- if (logf != NULL) {
- rewind(logf);
- logf = NULL;
- }
-
if (ret != 0 || tas_data[0] == NULL || tas_data_size[0] <= 0) {
fprintf(stderr, "failed fo parse %s\n", tasfn);
return 1;
}
+
+ // separate file with p2 input?
+ if (f_p2 != NULL) {
+ ret = import_raw(f_p2, &tas_data[1], &tas_data_size[1], NULL);
+ if (ret != 0 || tas_data[1] == NULL || tas_data_size[1] <= 0) {
+ fprintf(stderr, "failed fo parse %s\n", tasfn_p2);
+ return 1;
+ }
+ fclose(f_p2);
+ separate_2p = 1;
+ }
+
+ if (logf != NULL) {
+ fclose(logf);
+ logf = NULL;
+ }
+
if (tas_data_size[1] != 0 && tas_data[1] == NULL) {
fprintf(stderr, "missing tas_data[1]\n");
return 1;
pkt_out.enable.no_start_seq = no_start_seq;
if (use_vsync)
pkt_out.enable.inc_mode = INC_MODE_VSYNC;
+ else if (tas_data_size[1] != 0 && separate_2p)
+ pkt_out.enable.inc_mode = INC_MODE_SEPARATE;
else if (tas_data_size[1] != 0)
pkt_out.enable.inc_mode = INC_MODE_SHARED_PL2;
else
g.edge_cnt++;
}
-static noinline void do_to_step(void)
+static noinline void do_to_step_pl1(void)
{
g.frame_cnt++;
GPIOD_PDOR = g.stream_to[0][g.pos_to_p[0].o][th];
if (th)
- do_to_step();
+ do_to_step_pl1();
}
static void pl1th_isr_do_to(void)
GPIOB_PDOR = PL2_ADJ(v);
}
-static void pl2th_isr_do_to(void)
+static noinline void do_to_step_pl2(void)
+{
+ g.pos_to_p[1].o = (g.pos_to_p[1].o + 1) & STREAM_BUF_MASK;
+ if (g.pos_to_p[1].o == g.pos_to_p[1].i)
+ // done
+ choose_isrs_idle();
+}
+
+static void pl2th_isr_do_to_inc(void)
+{
+ uint32_t isfr, th, v;
+
+ isfr = PL2_ISFR;
+ PL2_ISFR = isfr;
+ th = PL2_TH();
+
+ v = g.stream_to[1][g.pos_to_p[1].o][th];
+ GPIOB_PDOR = PL2_ADJ(v);
+ if (th)
+ do_to_step_pl2();
+}
+
+static void pl2th_isr_do_to_p1d(void)
{
uint32_t isfr, th, v;
v = g.stream_to[1][g.pos_to_p[1].o][th];
GPIOB_PDOR = PL2_ADJ(v);
if (th) {
- do_to_step();
+ do_to_step_pl1();
g.pos_to_p[1].o = g.pos_to_p[0].o;
}
}
switch (g.inc_mode) {
case INC_MODE_VSYNC:
pl1th_handler = pl1th_isr_do_to;
- pl2th_handler = pl2th_isr_do_to;
+ pl2th_handler = pl2th_isr_do_to_p1d;
vsync_handler = vsync_isr_frameinc;
break;
case INC_MODE_SHARED_PL1:
pl1th_handler = pl1th_isr_do_to_inc;
- pl2th_handler = pl2th_isr_do_to;
+ pl2th_handler = pl2th_isr_do_to_p1d;
break;
case INC_MODE_SHARED_PL2:
pl1th_handler = pl1th_isr_do_to;
pl2th_handler = pl2th_isr_do_to_inc_pl1;
break;
+ case INC_MODE_SEPARATE:
+ pl1th_handler = pl1th_isr_do_to_inc;
+ pl2th_handler = pl2th_isr_do_to_inc;
+ break;
}
}
else if (g.stream_enable_from) {
pl1th_handler = pl1th_isr_fixed_do_from;
break;
case INC_MODE_SHARED_PL2:
+ case INC_MODE_SEPARATE:
/* TODO */
break;
}
g.pos_to_p[i].i = g.pos_to_p[i].o = 0;
g.pos_from.i = g.pos_from.o = 0;
g.frame_cnt = 0;
+ memset(g.stream_to[1], 0x3f, sizeof(g.stream_to[1]));
choose_isrs_idle();
}
if (g.stream_enable_to && !g.stream_ended) {
check_get_data(0);
- if (g.inc_mode == INC_MODE_SHARED_PL2)
+ if (g.inc_mode == INC_MODE_SHARED_PL2
+ || g.inc_mode == INC_MODE_SEPARATE)
check_get_data(1);
}