xref: /reactos/hal/halx86/pc98/beep.c (revision 40462c92)
1 /*
2  * PROJECT:     NEC PC-98 series HAL
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Speaker support (beeping)
5  * COPYRIGHT:   Copyright 2020 Dmitry Borisov (di.sean@protonmail.com)
6  */
7 
8 /* INCLUDES ******************************************************************/
9 
10 #include <hal.h>
11 
12 #define NDEBUG
13 #include <debug.h>
14 
15 /* FUNCTIONS *****************************************************************/
16 
17 BOOLEAN
18 NTAPI
19 HalMakeBeep(
20     _In_ ULONG Frequency)
21 {
22     TIMER_CONTROL_PORT_REGISTER TimerControl;
23     ULONG Divider;
24     BOOLEAN Success = FALSE;
25 
26     HalpAcquireCmosSpinLock();
27 
28     __outbyte(PPI_IO_o_CONTROL, PPI_TIMER_1_UNGATE_TO_SPEAKER);
29 
30     if (Frequency)
31     {
32         Divider = PIT_FREQUENCY / Frequency;
33 
34         if (Divider <= 0x10000)
35         {
36             TimerControl.BcdMode = FALSE;
37             TimerControl.OperatingMode = PitOperatingMode3;
38             TimerControl.Channel = PitChannel1;
39             TimerControl.AccessMode = PitAccessModeLowHigh;
40             __outbyte(TIMER_CONTROL_PORT, TimerControl.Bits);
41             __outbyte(TIMER_CHANNEL1_DATA_PORT, FIRSTBYTE(Divider));
42             __outbyte(TIMER_CHANNEL1_DATA_PORT, SECONDBYTE(Divider));
43 
44             __outbyte(PPI_IO_o_CONTROL, PPI_TIMER_1_GATE_TO_SPEAKER);
45 
46             Success = TRUE;
47         }
48     }
49 
50     HalpReleaseCmosSpinLock();
51 
52     return Success;
53 }
54