comparison 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
comparison
equal deleted inserted replaced
823:9092ff68e37d 824:158dd05fb9f9
1 #include "types.h" 1 #include "types.h"
2 #include "melody.h" 2 #include "melody.h"
3 3
4 extern struct melentry *melody_buf_start, *melody_buf_tailptr; 4 extern struct melentry *melody_buf_start, *melody_buf_tailptr;
5 extern int melody_mode;
5 6
6 #define ARMIO_LOAD_TIM (*(volatile u16 *) 0xFFFE4808) 7 #define ARMIO_LOAD_TIM (*(volatile u16 *) 0xFFFE4808)
7 #define BUZZ_LIGHT_REG (*(volatile u16 *) 0xFFFE480E) 8 #define BUZZ_LIGHT_REG (*(volatile u16 *) 0xFFFE480E)
8 9
10 #define PWT_FRC_REG (*(volatile u8 *) 0xFFFE8800)
11 #define PWT_VCR_REG (*(volatile u8 *) 0xFFFE8801)
12
9 void 13 void
10 melody_play() 14 melody_play_bu()
11 { 15 {
12 struct melentry *p; 16 struct melentry *p;
13 int count; 17 int count;
14 18
15 wait_for_tdma_frame(); 19 wait_for_tdma_frame();
22 for (count = p->dur; count; count--) 26 for (count = p->dur; count; count--)
23 wait_for_tdma_frame(); 27 wait_for_tdma_frame();
24 BUZZ_LIGHT_REG = 0; 28 BUZZ_LIGHT_REG = 0;
25 } 29 }
26 } 30 }
31
32 void
33 melody_play_pwt()
34 {
35 struct melentry *p;
36 int count;
37
38 wait_for_tdma_frame();
39 for (p = melody_buf_start; p < melody_buf_tailptr; p++) {
40 PWT_FRC_REG = p->tone;
41 PWT_VCR_REG = p->vol;
42 for (count = p->dur; count; count--)
43 wait_for_tdma_frame();
44 PWT_VCR_REG = 0;
45 }
46 }
47
48 void
49 melody_play()
50 {
51 switch (melody_mode) {
52 case 1:
53 melody_play_bu();
54 return;
55 case 2:
56 melody_play_pwt();
57 return;
58 default:
59 printf("ERROR: no melody entered\n");
60 }
61 }