From: notaz Date: Tue, 25 Nov 2014 00:27:08 +0000 (+0200) Subject: support 2nd player streaming from separate raw file X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;p=teensytas.git support 2nd player streaming from separate raw file --- diff --git a/host/main.c b/host/main.c index b5a65b1..bf6966d 100644 --- a/host/main.c +++ b/host/main.c @@ -642,7 +642,7 @@ unhandled_line: 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; @@ -654,7 +654,7 @@ static int import_raw(FILE *f, uint8_t *out[2], int out_byte_count[2], 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) { @@ -683,8 +683,8 @@ static int import_raw(FILE *f, uint8_t *out[2], int out_byte_count[2], 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; } @@ -693,7 +693,7 @@ static int import_raw(FILE *f, uint8_t *out[2], int out_byte_count[2], if (logf) fwrite(&val, 1, 1, logf); - out[0][count++] = val & 0x3f; + (*out)[count++] = val & 0x3f; continue; bad: @@ -702,7 +702,7 @@ bad: } printf("loaded raw, %d bytes\n", count); - out_byte_count[0] = count; + *out_byte_count = count; return 0; } @@ -772,12 +772,14 @@ int main(int argc, char *argv[]) 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; @@ -801,6 +803,12 @@ int main(int argc, char *argv[]) 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) @@ -859,9 +867,9 @@ int main(int argc, char *argv[]) } if (tasfn != NULL) { + FILE *f, *f_p2 = NULL; const char *ext; long size; - FILE *f; f = fopen(tasfn, "rb"); if (f == NULL) { @@ -870,6 +878,15 @@ int main(int argc, char *argv[]) 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); @@ -889,22 +906,34 @@ int main(int argc, char *argv[]) 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; @@ -1130,6 +1159,8 @@ int main(int argc, char *argv[]) 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 diff --git a/main.c b/main.c index 2aae65a..c05eb3b 100644 --- a/main.c +++ b/main.c @@ -105,7 +105,7 @@ static void pl1th_isr_fixed(void) g.edge_cnt++; } -static noinline void do_to_step(void) +static noinline void do_to_step_pl1(void) { g.frame_cnt++; @@ -125,7 +125,7 @@ static void pl1th_isr_do_to_inc(void) 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) @@ -157,7 +157,29 @@ static void pl2th_isr_fixed(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; @@ -182,7 +204,7 @@ static void pl2th_isr_do_to_inc_pl1(void) 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; } } @@ -264,17 +286,21 @@ static void choose_isrs(void) 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) { @@ -287,6 +313,7 @@ static void choose_isrs(void) pl1th_handler = pl1th_isr_fixed_do_from; break; case INC_MODE_SHARED_PL2: + case INC_MODE_SEPARATE: /* TODO */ break; } @@ -406,6 +433,7 @@ static void clear_state(void) 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(); } @@ -595,7 +623,8 @@ int main(void) 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); } diff --git a/pkts.h b/pkts.h index 4c25019..582fa72 100644 --- a/pkts.h +++ b/pkts.h @@ -34,4 +34,5 @@ enum inc_mode { // shared stream index incremented by pl1 or pl2 INC_MODE_SHARED_PL1 = 1, INC_MODE_SHARED_PL2 = 2, + INC_MODE_SEPARATE = 3, };