changeset 823:9092ff68e37d

buzplayer: implement PWT mode melody entry
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 30 May 2021 04:42:05 +0000
parents 7c02cc7f28df
children 158dd05fb9f9
files target-utils/buzplayer/cmdtab.c target-utils/buzplayer/main.c target-utils/buzplayer/melentry.c target-utils/buzplayer/melody.h
diffstat 4 files changed, 74 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/target-utils/buzplayer/cmdtab.c	Sun May 30 04:11:17 2021 +0000
+++ b/target-utils/buzplayer/cmdtab.c	Sun May 30 04:42:05 2021 +0000
@@ -20,12 +20,18 @@
 extern void abb_unlock_page2();
 
 extern void melody_init();
+extern void melody_init_pwt();
 extern void melody_entry();
 extern void melody_play();
+extern void pwt_entry_note();
+extern void pwt_entry_rest();
 
 const struct cmdtab cmdtab[] = {
 	{"E", melody_entry},
+	{"EP", pwt_entry_rest},
+	{"ET", pwt_entry_note},
 	{"I", melody_init},
+	{"IT", melody_init_pwt},
 	{"P", melody_play},
 	{"abbinit", abb_init},
 	{"abbpage2", abb_unlock_page2},
--- a/target-utils/buzplayer/main.c	Sun May 30 04:11:17 2021 +0000
+++ b/target-utils/buzplayer/main.c	Sun May 30 04:42:05 2021 +0000
@@ -4,6 +4,7 @@
 extern char _end[];
 
 struct melentry *melody_buf_start, *melody_buf_tailptr;
+int melody_mode;
 
 main()
 {
--- 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++;
+}
--- a/target-utils/buzplayer/melody.h	Sun May 30 04:11:17 2021 +0000
+++ b/target-utils/buzplayer/melody.h	Sun May 30 04:42:05 2021 +0000
@@ -1,4 +1,5 @@
 struct melentry {
-	u16	tone;
+	u8	tone;
+	u8	vol;
 	u16	dur;
 };