diff target-utils/buzplayer/melplay.c @ 824:158dd05fb9f9

buzplayer: implement PWT mode melody play
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 30 May 2021 04:50:30 +0000
parents 8a200d65c6a0
children
line wrap: on
line diff
--- a/target-utils/buzplayer/melplay.c	Sun May 30 04:42:05 2021 +0000
+++ b/target-utils/buzplayer/melplay.c	Sun May 30 04:50:30 2021 +0000
@@ -2,12 +2,16 @@
 #include "melody.h"
 
 extern struct melentry *melody_buf_start, *melody_buf_tailptr;
+extern int melody_mode;
 
 #define	ARMIO_LOAD_TIM	(*(volatile u16 *) 0xFFFE4808)
 #define	BUZZ_LIGHT_REG	(*(volatile u16 *) 0xFFFE480E)
 
+#define	PWT_FRC_REG	(*(volatile u8 *) 0xFFFE8800)
+#define	PWT_VCR_REG	(*(volatile u8 *) 0xFFFE8801)
+
 void
-melody_play()
+melody_play_bu()
 {
 	struct melentry *p;
 	int count;
@@ -24,3 +28,34 @@
 		BUZZ_LIGHT_REG = 0;
 	}
 }
+
+void
+melody_play_pwt()
+{
+	struct melentry *p;
+	int count;
+
+	wait_for_tdma_frame();
+	for (p = melody_buf_start; p < melody_buf_tailptr; p++) {
+		PWT_FRC_REG = p->tone;
+		PWT_VCR_REG = p->vol;
+		for (count = p->dur; count; count--)
+			wait_for_tdma_frame();
+		PWT_VCR_REG = 0;
+	}
+}
+
+void
+melody_play()
+{
+	switch (melody_mode) {
+	case 1:
+		melody_play_bu();
+		return;
+	case 2:
+		melody_play_pwt();
+		return;
+	default:
+		printf("ERROR: no melody entered\n");
+	}
+}