FreeCalypso > hg > freecalypso-tools
changeset 893:85091e14be9c
fc-buzplay: PWT refactoring, first step
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Apr 2022 08:00:50 +0000 |
parents | 110749b39ea2 |
children | 7ade15d4e0cb |
files | loadtools/bpdispatch.c loadtools/buzplaypwt.c |
diffstat | 2 files changed, 35 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/loadtools/bpdispatch.c Sun Apr 03 05:42:29 2022 +0000 +++ b/loadtools/bpdispatch.c Sun Apr 03 08:00:50 2022 +0000 @@ -11,7 +11,7 @@ extern int cmd_baud(); extern int cmd_exit(); extern int cmd_play(); -extern int cmd_playt(); +extern int cmd_play_pwt(); extern int loadtool_cmd_passthru(); static struct cmdtab { @@ -26,7 +26,8 @@ {"buzlev", 0, 1, loadtool_cmd_passthru}, {"exit", 0, 1, cmd_exit}, {"play", 1, 1, cmd_play}, - {"playt", 1, 2, cmd_playt}, + {"play-pwt", 1, 2, cmd_play_pwt}, + {"playt", 1, 2, cmd_play_pwt}, {"pwt", 1, 1, loadtool_cmd_passthru}, {"quit", 0, 1, cmd_exit}, {"r8", 1, 1, loadtool_cmd_passthru},
--- a/loadtools/buzplaypwt.c Sun Apr 03 05:42:29 2022 +0000 +++ b/loadtools/buzplaypwt.c Sun Apr 03 08:00:50 2022 +0000 @@ -66,32 +66,24 @@ {0, -1} }; -cmd_playt(argc, argv) - char **argv; +buzplay_pwt_file(filename, global_vol) + char *filename; + unsigned global_vol; { FILE *f; char linebuf[256], *cp, *fields[3]; int lineno, nfields; char *targv[5], argbuf1[16], argbuf2[16], argbuf3[16]; struct pwt_note *tp; - u_long global_vol, note_vol, duration, total_ms; + unsigned note_vol, duration; + u_long total_ms; int rc, timeout; - f = fopen(argv[1], "r"); + f = fopen(filename, "r"); if (!f) { - perror(argv[1]); + perror(filename); return(-1); } - if (argv[2]) { - global_vol = strtoul(argv[2], 0, 0); - if (global_vol < 1 || global_vol > 64) { - fprintf(stderr, - "error: invalid global volume argument\n"); - fclose(f); - return(-1); - } - } else - global_vol = 64; printf("Uploading the melody to the target\n"); targv[0] = "IT"; targv[1] = 0; @@ -110,7 +102,7 @@ cp = index(linebuf, '\n'); if (!cp) { fprintf(stderr, "%s line %d: missing newline\n", - argv[1], lineno); + filename, lineno); fclose(f); return(-1); } @@ -123,7 +115,7 @@ break; if (nfields >= 3) { fprintf(stderr, "%s line %d: too many fields\n", - argv[1], lineno); + filename, lineno); fclose(f); return(-1); } @@ -142,7 +134,7 @@ if (tp->code < 0) { fprintf(stderr, "%s line %d: invalid note name\n", - argv[1], lineno); + filename, lineno); fclose(f); return(-1); } @@ -150,7 +142,7 @@ if (note_vol < 1 || note_vol > 64) { fprintf(stderr, "%s line %d: invalid note volume\n", - argv[1], lineno); + filename, lineno); fclose(f); return(-1); } @@ -158,7 +150,7 @@ if (duration < 1 || duration > 0xFFFF) { fprintf(stderr, "%s line %d: the duration number is out of range\n", - argv[1], lineno); + filename, lineno); fclose(f); return(-1); } @@ -176,7 +168,7 @@ if (duration < 1 || duration > 0xFFFF) { fprintf(stderr, "%s line %d: the duration number is out of range\n", - argv[1], lineno); + filename, lineno); fclose(f); return(-1); } @@ -186,7 +178,7 @@ targv[2] = 0; } else { fprintf(stderr, "%s line %d: invalid syntax\n", - argv[1], lineno); + filename, lineno); fclose(f); return(-1); } @@ -206,7 +198,7 @@ } fclose(f); if (!total_ms) { - fprintf(stderr, "%s is empty!\n", argv[1]); + fprintf(stderr, "%s is empty!\n", filename); return(-1); } printf("Requesting play of the uploaded melody on the target\n"); @@ -218,3 +210,20 @@ timeout = total_ms / 1000 + 2; return tpinterf_pass_output(timeout); } + +cmd_play_pwt(argc, argv) + char **argv; +{ + unsigned global_vol; + + if (argv[2]) { + global_vol = strtoul(argv[2], 0, 0); + if (global_vol < 1 || global_vol > 64) { + fprintf(stderr, + "error: invalid global volume argument\n"); + return(-1); + } + } else + global_vol = 64; + return buzplay_pwt_file(argv[1], global_vol); +}