diff target-utils/buzplayer/melentry.c @ 823:9092ff68e37d

buzplayer: implement PWT mode melody entry
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 30 May 2021 04:42:05 +0000
parents eb5960dc258c
children
line wrap: on
line diff
--- a/target-utils/buzplayer/melentry.c	Sun May 30 04:11:17 2021 +0000
+++ b/target-utils/buzplayer/melentry.c	Sun May 30 04:42:05 2021 +0000
@@ -5,11 +5,22 @@
 #include "melody.h"
 
 extern struct melentry *melody_buf_start, *melody_buf_tailptr;
+extern int melody_mode;
 
 void
 melody_init()
 {
 	melody_buf_tailptr = melody_buf_start;
+	melody_mode = 1;
+	pwt_off();
+}
+
+void
+melody_init_pwt()
+{
+	melody_buf_tailptr = melody_buf_start;
+	melody_mode = 2;
+	pwt_on();
 }
 
 void
@@ -19,6 +30,10 @@
 	char *argv[3];
 	u32 tone, dur;
 
+	if (melody_mode != 1) {
+		printf("ERROR: wrong mode for melody entry\n");
+		return;
+	}
 	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
 		return;
 	tone = strtoul(argv[0], 0, 0);
@@ -31,3 +46,53 @@
 	melody_buf_tailptr->dur = dur;
 	melody_buf_tailptr++;
 }
+
+void
+pwt_entry_note(argbulk)
+	char *argbulk;
+{
+	char *argv[4];
+	u32 tone, vol, dur;
+
+	if (melody_mode != 2) {
+		printf("ERROR: wrong mode for melody entry\n");
+		return;
+	}
+	if (parse_args(argbulk, 3, 3, argv, 0) < 0)
+		return;
+	tone = strtoul(argv[0], 0, 0);
+	vol = strtoul(argv[1], 0, 0);
+	dur = strtoul(argv[2], 0, 0);
+	if (tone > 47 || vol > 63 || dur < 1 || dur > 0xFFFF) {
+		printf("ERROR: argument(s) out of range\n");
+		return;
+	}
+	melody_buf_tailptr->tone = tone;
+	melody_buf_tailptr->vol = (vol << 1) | 1;
+	melody_buf_tailptr->dur = dur;
+	melody_buf_tailptr++;
+}
+
+void
+pwt_entry_rest(argbulk)
+	char *argbulk;
+{
+	char *argv[2];
+	u32 dur;
+
+	if (melody_mode != 2) {
+		printf("ERROR: wrong mode for melody entry\n");
+		return;
+	}
+	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
+		return;
+	dur = strtoul(argv[0], 0, 0);
+	if (dur < 1 || dur > 0xFFFF) {
+		printf("ERROR: argument out of range\n");
+		return;
+	}
+	melody_buf_tailptr->tone = 0;
+	melody_buf_tailptr->vol = 0;
+	melody_buf_tailptr->dur = dur;
+	melody_buf_tailptr++;
+}