IoCreateFile(): Fixed missing init of field: FsContext,FsContext2
[reactos.git] / hal / halx86 / beep.c
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS kernel
4  * FILE:            ntoskrnl/hal/x86/beep.c
5  * PURPOSE:         Speaker function (it's only one)
6  * PROGRAMMER:      Eric Kohl (ekohl@abo.rhein-zeitung.de)
7  * UPDATE HISTORY:
8  *                  Created 31/01/99
9  */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ddk/ntddk.h>
14
15 #define NDEBUG
16 #include <internal/debug.h>
17
18
19 /* CONSTANTS *****************************************************************/
20
21 #define TIMER2     0x42
22 #define TIMER3     0x43
23 #define PORT_B     0x61
24 #define CLOCKFREQ  1193167
25
26
27 /* FUNCTIONS *****************************************************************/
28 /*
29  * FUNCTION: Beeps the speaker.
30  * ARGUMENTS:
31  *       Frequency = If 0, the speaker will be switched off, otherwise
32  *                   the speaker beeps with the specified frequency.
33  */
34
35 BOOLEAN
36 STDCALL
37 HalMakeBeep (
38         ULONG   Frequency
39         )
40 {
41    UCHAR b;
42    
43     /* save flags and disable interrupts */
44     __asm__("pushf\n\t" \
45             "cli\n\t");
46
47     /* speaker off */
48     b = READ_PORT_UCHAR((PUCHAR)PORT_B);
49     WRITE_PORT_UCHAR((PUCHAR)PORT_B, b & 0xFC);
50
51     if (Frequency)
52     {
53         DWORD Divider = CLOCKFREQ / Frequency;
54
55         if (Divider > 0x10000)
56         {
57             /* restore flags */
58             __asm__("popf\n\t");
59
60             return FALSE;
61         }
62
63         /* set timer divider */
64         WRITE_PORT_UCHAR((PUCHAR)TIMER3, 0xB6);
65         WRITE_PORT_UCHAR((PUCHAR)TIMER2, (UCHAR)(Divider & 0xFF));
66         WRITE_PORT_UCHAR((PUCHAR)TIMER2, (UCHAR)((Divider>>8) & 0xFF));
67
68         /* speaker on */
69         WRITE_PORT_UCHAR((PUCHAR)PORT_B, READ_PORT_UCHAR((PUCHAR)PORT_B) | 0x03);
70     }
71
72     /* restore flags */
73     __asm__("popf\n\t");
74
75     return TRUE;
76 }
77