-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsound.c
More file actions
54 lines (52 loc) · 1.26 KB
/
sound.c
File metadata and controls
54 lines (52 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "sound.h"
#include "memory.h"
void sound(uint16_t period, uint16_t durance)
{
asm volatile (
"mov %[period], r1\n\t"
"mov %[durance], r2\n\t"
"mov $0100, r3\n\t"
"clr r0\n\t"
".l1_%=:\n\t"
"mov r1, r4\n"
"mov r0, @$-062\n\t"
"xor r3, r0\n\t"
".l2_%=:\n\t"
"sob r4, .l2_%=\n\t"
"sob r2, .l1_%=\n\t"
:
: [period]"g"(period), [durance]"g"(durance)
: "r0", "r1", "r2", "r3", "r4", "cc", "memory"
);
}
void sound_vibrato(uint16_t period, uint16_t durance)
{
asm volatile (
"mov %[period], r1\n\t"
"mov %[durance], r2\n\t"
"mov $0100, r3\n\t"
"mov r1, r5\n\t"
"asr r5\n\t"
"asr r5\n\t"
"asr r5\n\t"
"neg r5\n\t"
"add r1, r5\n\t"
"clr r0\n"
".l1_%=:\n\t"
"mov r1, r4\n\t"
"mov r0, @$-062\n\t"
"bit $0100, r0\n\t"
"beq .l_long_%=\n\t"
"sub r5, r4\n\t"
"br .l_inner_%=\n"
".l_long_%=:\n\t"
"add r5, r4\n"
".l_inner_%=:\n\t"
"sob r4, .l_inner_%=\n\t"
"xor r3, r0\n\t"
"sob r2, .l1_%=\n\t"
:
: [period]"g"(period), [durance]"g"(durance)
: "r0", "r1", "r2", "r3", "r4", "r5", "cc", "memory"
);
}