forked from cirosantilli/x86-bare-metal-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pc_speaker.S
37 lines (30 loc) · 778 Bytes
/
pc_speaker.S
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
/* https://github.com/cirosantilli/x86-bare-metal-examples# */
#include "common.h"
BEGIN
/* Chanel 2, square wave, load TODO?, binary */
mov $0xb6, %al
out %al, $0x43
/* Set frequency of Channel 2. */
.equ div, 1193181 / 1000
mov div, %ax
out %al, $0x42
mov %ah, %al
out %al, $0x42
/* Dummy read of System Control Port B. TODO why? */
in $0x61, %al
/* Enable timer 2 output to speaker.
* THIS is where the sound begins.
*/
mov $0x03, %al
out %al, $0x61
/* Loop forever to keep hearing it. */
loop:
nop
jmp loop
/* This is how a sound can be stopped.
* This code never reached in this example.
* unless you hack it up.
*/
in $0x61, %al
mov $0x00, %al
out %al, $0x61