diff ringtools/fc-e1gen.c @ 175:b002c7cf5d03

fc-e1gen: support parenthesized options for bit0 and dummy time byte
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 25 Mar 2017 18:36:37 +0000
parents c138906889f7
children 2133c475f5bd
line wrap: on
line diff
--- a/ringtools/fc-e1gen.c	Thu Mar 23 16:05:55 2017 +0000
+++ b/ringtools/fc-e1gen.c	Sat Mar 25 18:36:37 2017 +0000
@@ -82,6 +82,24 @@
 	return val;
 }
 
+input_paren_number(str, min, max)
+	char *str;
+{
+	char *cp;
+
+	if (str[0] != '(') {
+badparen:	fprintf(stderr,
+			"%s line %d: bad parenthesized argument \"%s\"\n",
+			infname, lineno, str);
+		exit(1);
+	}
+	cp = index(str, ')');
+	if (!cp || cp[1])
+		goto badparen;
+	*cp = '\0';
+	return input_number(str + 1, min, max);
+}
+
 handle_time_line()
 {
 	if (nfields != 2) {
@@ -109,6 +127,7 @@
 	int amp, freq, length;
 	int tremT0, tremFreq;
 	int sustain, t1, t2, t3, t5;
+	int bit0;
 
 	check_req_field(p);
 	oscn = input_number(fields[p], 0, 7);
@@ -123,6 +142,12 @@
 
 	/* basic part */
 	check_req_field(p);
+	if (fields[p][0] == '(') {
+		bit0 = input_paren_number(fields[p], 0, 1);
+		p++;
+		check_req_field(p);
+	} else
+		bit0 = 0;
 	if (!strcmp(fields[p], "df")) {
 		p++;
 		check_req_field(p);
@@ -131,10 +156,10 @@
 		check_req_field(p);
 		amp = input_number(fields[p], 0, 1023);
 		p++;
-		word0 = freq << 2 | 2;
+		word0 = freq << 2 | 2 | bit0;
 		word1 = amp << 6;
 	} else {
-		word0 = 0;
+		word0 = bit0;
 		if (!strcmp(fields[p], "sq1")) {
 			p++;
 			word0 |= 4;
@@ -250,6 +275,7 @@
 {
 	int p;
 	int oscn, osc_bit;
+	int dummy_time_byte;
 
 	do
 		get_input_line();
@@ -260,16 +286,24 @@
 		exit(1);
 	}
 	if (nfields < 2) {
-		fprintf(stderr, "%s line %d: osc-set must be non-empty\n",
+emptyerr:	fprintf(stderr, "%s line %d: osc-set must be non-empty\n",
 			infname, lineno);
 		exit(1);
 	}
-	for (p = 1; p < nfields; p++) {
+	p = 1;
+	if (fields[p][0] == '(') {
+		dummy_time_byte = input_paren_number(fields[p], 0, 255);
+		p++;
+		if (nfields < 3)
+			goto emptyerr;
+	} else
+		dummy_time_byte = 0;
+	for (; p < nfields; p++) {
 		oscn = input_number(fields[p], 0, 7);
 		osc_bit = 1 << oscn;
 		global_osc_set |= osc_bit;
 	}
-	putc(0, outf);
+	putc(dummy_time_byte, outf);
 	putc(global_osc_set, outf);
 }