-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsound.c
More file actions
34 lines (28 loc) · 773 Bytes
/
Copy pathsound.c
File metadata and controls
34 lines (28 loc) · 773 Bytes
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
#include "types.h"
static inline uint8_t inb(uint16_t port) {
uint8_t ret;
__asm__ __volatile__ ("inb %1, %0" : "=a"(ret) : "Nd"(port));
return ret;
}
static inline void outb(uint16_t port, uint8_t val) {
__asm__ __volatile__ ("outb %0, %1" : : "a"(val), "Nd"(port));
}
void play_sound(uint32_t frequency) {
uint32_t divisor = 1193182 / frequency;
outb(0x43, 0xB6);
outb(0x42, (uint8_t)(divisor & 0xFF));
outb(0x42, (uint8_t)((divisor >> 8) & 0xFF));
uint8_t tmp = inb(0x61);
if (tmp != (tmp | 3)) {
outb(0x61, tmp | 3);
}
}
void nosound(void) {
uint8_t tmp = inb(0x61) & 0xFC;
outb(0x61, tmp);
}
void beep(void) {
play_sound(750);
for (volatile uint32_t i = 0; i < 50000000; i++);
nosound();
}