# HG changeset patch # User Mychaela Falconia # Date 1648973465 0 # Node ID 7ade15d4e0cb511f0b11a446bfd6b0efc6f46ac4 # Parent 85091e14be9cbc933ff95fec287900780e9780c4 fc-buzplay: BU refactoring, first step diff -r 85091e14be9c -r 7ade15d4e0cb loadtools/Makefile --- a/loadtools/Makefile Sun Apr 03 08:00:50 2022 +0000 +++ b/loadtools/Makefile Sun Apr 03 08:11:05 2022 +0000 @@ -27,7 +27,7 @@ labaud.o lacrc32.o romload.o secondprog.o srecreader.o \ tpinterf.o tpinterf2.o tpinterfb.o ttypassthru.o -BUZPLAY_OBJS= bpdispatch.o bpmain.o buzplay.o buzplaypwt.o compalload.o \ +BUZPLAY_OBJS= bpdispatch.o bpmain.o buzplaybu.o buzplaypwt.o compalload.o \ defpath.o flashstubs.o hexdecode.o hwparam.o labaud.o ltexit.o \ ltpassthru.o romload.o srecreader.o tpinterf.o diff -r 85091e14be9c -r 7ade15d4e0cb loadtools/bpdispatch.c --- a/loadtools/bpdispatch.c Sun Apr 03 08:00:50 2022 +0000 +++ b/loadtools/bpdispatch.c Sun Apr 03 08:11:05 2022 +0000 @@ -10,7 +10,7 @@ extern int cmd_baud(); extern int cmd_exit(); -extern int cmd_play(); +extern int cmd_play_bu(); extern int cmd_play_pwt(); extern int loadtool_cmd_passthru(); @@ -25,7 +25,8 @@ {"baud", 0, 1, cmd_baud}, {"buzlev", 0, 1, loadtool_cmd_passthru}, {"exit", 0, 1, cmd_exit}, - {"play", 1, 1, cmd_play}, + {"play", 1, 1, cmd_play_bu}, + {"play-bu", 1, 1, cmd_play_bu}, {"play-pwt", 1, 2, cmd_play_pwt}, {"playt", 1, 2, cmd_play_pwt}, {"pwt", 1, 1, loadtool_cmd_passthru}, diff -r 85091e14be9c -r 7ade15d4e0cb loadtools/buzplay.c --- a/loadtools/buzplay.c Sun Apr 03 08:00:50 2022 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -/* - * The actual functionality of fc-buzplay is implemented here. - */ - -#include -#include -#include -#include -#include -#include - -cmd_play(argc, argv) - char **argv; -{ - FILE *f; - char linebuf[256], *cp, *num1, *num2; - int lineno; - char *targv[4]; - u_long n1, n2, total_ms; - int rc, timeout; - - f = fopen(argv[1], "r"); - if (!f) { - perror(argv[1]); - return(-1); - } - printf("Uploading the melody to the target\n"); - targv[0] = "I"; - targv[1] = 0; - tpinterf_make_cmd(targv); - if (tpinterf_send_cmd() < 0) { - fclose(f); - return(-1); - } - rc = tpinterf_pass_output(1); - if (rc) { - fclose(f); - return(rc); - } - targv[0] = "E"; - targv[3] = 0; - total_ms = 0; - for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { - cp = index(linebuf, '\n'); - if (!cp) { - fprintf(stderr, "%s line %d: missing newline\n", - argv[1], lineno); - fclose(f); - return(-1); - } - for (cp = linebuf; isspace(*cp); cp++) - ; - if (*cp == '\0' || *cp == '#') - continue; - if (!isdigit(*cp)) { -inv: fprintf(stderr, "%s line %d: unexpected content\n", - argv[1], lineno); - fclose(f); - return(-1); - } - for (num1 = cp; *cp && !isspace(*cp); cp++) - if (!isdigit(*cp)) - goto inv; - if (isspace(*cp)) - *cp++ = '\0'; - while (isspace(*cp)) - cp++; - if (!isdigit(*cp)) - goto inv; - for (num2 = cp; *cp && !isspace(*cp); cp++) - if (!isdigit(*cp)) - goto inv; - if (isspace(*cp)) - *cp++ = '\0'; - while (isspace(*cp)) - cp++; - if (*cp != '\0' && *cp != '#') - goto inv; - n1 = strtoul(num1, 0, 10); - n2 = strtoul(num2, 0, 10); - if (n1 > 255) { - fprintf(stderr, - "%s line %d: the tone number is out of range\n", - argv[1], lineno); - fclose(f); - return(-1); - } - if (n2 < 1 || n2 > 0xFFFF) { - fprintf(stderr, - "%s line %d: the duration number is out of range\n", - argv[1], lineno); - fclose(f); - return(-1); - } - /* send it to the target */ - targv[1] = num1; - targv[2] = num2; - tpinterf_make_cmd(targv); - if (tpinterf_send_cmd() < 0) { - fclose(f); - return(-1); - } - rc = tpinterf_pass_output(1); - if (rc) { - fclose(f); - return(rc); - } - /* account for the duration */ - total_ms += n2 * 5; - } - fclose(f); - if (!total_ms) { - fprintf(stderr, "%s is empty!\n", argv[1]); - return(-1); - } - printf("Requesting play of the uploaded melody on the target\n"); - targv[0] = "P"; - targv[1] = 0; - tpinterf_make_cmd(targv); - if (tpinterf_send_cmd() < 0) - return(-1); - timeout = total_ms / 1000 + 2; - return tpinterf_pass_output(timeout); -} diff -r 85091e14be9c -r 7ade15d4e0cb loadtools/buzplaybu.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loadtools/buzplaybu.c Sun Apr 03 08:11:05 2022 +0000 @@ -0,0 +1,130 @@ +/* + * fc-buzplay: this module implements the legacy BU mode. + */ + +#include +#include +#include +#include +#include +#include + +buzplay_bu_file(filename) + char *filename; +{ + FILE *f; + char linebuf[256], *cp, *num1, *num2; + int lineno; + char *targv[4]; + u_long n1, n2, total_ms; + int rc, timeout; + + f = fopen(filename, "r"); + if (!f) { + perror(filename); + return(-1); + } + printf("Uploading the melody to the target\n"); + targv[0] = "I"; + targv[1] = 0; + tpinterf_make_cmd(targv); + if (tpinterf_send_cmd() < 0) { + fclose(f); + return(-1); + } + rc = tpinterf_pass_output(1); + if (rc) { + fclose(f); + return(rc); + } + targv[0] = "E"; + targv[3] = 0; + total_ms = 0; + for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { + cp = index(linebuf, '\n'); + if (!cp) { + fprintf(stderr, "%s line %d: missing newline\n", + filename, lineno); + fclose(f); + return(-1); + } + for (cp = linebuf; isspace(*cp); cp++) + ; + if (*cp == '\0' || *cp == '#') + continue; + if (!isdigit(*cp)) { +inv: fprintf(stderr, "%s line %d: unexpected content\n", + filename, lineno); + fclose(f); + return(-1); + } + for (num1 = cp; *cp && !isspace(*cp); cp++) + if (!isdigit(*cp)) + goto inv; + if (isspace(*cp)) + *cp++ = '\0'; + while (isspace(*cp)) + cp++; + if (!isdigit(*cp)) + goto inv; + for (num2 = cp; *cp && !isspace(*cp); cp++) + if (!isdigit(*cp)) + goto inv; + if (isspace(*cp)) + *cp++ = '\0'; + while (isspace(*cp)) + cp++; + if (*cp != '\0' && *cp != '#') + goto inv; + n1 = strtoul(num1, 0, 10); + n2 = strtoul(num2, 0, 10); + if (n1 > 255) { + fprintf(stderr, + "%s line %d: the tone number is out of range\n", + filename, lineno); + fclose(f); + return(-1); + } + if (n2 < 1 || n2 > 0xFFFF) { + fprintf(stderr, + "%s line %d: the duration number is out of range\n", + filename, lineno); + fclose(f); + return(-1); + } + /* send it to the target */ + targv[1] = num1; + targv[2] = num2; + tpinterf_make_cmd(targv); + if (tpinterf_send_cmd() < 0) { + fclose(f); + return(-1); + } + rc = tpinterf_pass_output(1); + if (rc) { + fclose(f); + return(rc); + } + /* account for the duration */ + total_ms += n2 * 5; + } + fclose(f); + if (!total_ms) { + fprintf(stderr, "%s is empty!\n", filename); + return(-1); + } + printf("Requesting play of the uploaded melody on the target\n"); + targv[0] = "P"; + targv[1] = 0; + tpinterf_make_cmd(targv); + if (tpinterf_send_cmd() < 0) + return(-1); + timeout = total_ms / 1000 + 2; + return tpinterf_pass_output(timeout); +} + +cmd_play_bu(argc, argv) + char **argv; +{ + buzplay_bu_file(argv[1]); +}