mirror of
https://github.com/reactos/reactos.git
synced 2025-06-27 20:09:44 +00:00
- Make HalMakeBeep a bit nicer by making the PUCHAR typedef part of the TIMER constants.
svn path=/trunk/; revision=24742
This commit is contained in:
parent
30c16d9652
commit
abe724dba9
1 changed files with 39 additions and 48 deletions
|
@ -1,77 +1,68 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
* FILE: ntoskrnl/hal/x86/beep.c
|
||||
* PURPOSE: Speaker function (it's only one)
|
||||
* PROGRAMMER: Eric Kohl (ekohl@abo.rhein-zeitung.de)
|
||||
* UPDATE HISTORY:
|
||||
* Created 31/01/99
|
||||
*/
|
||||
* PROJECT: ReactOS HAL
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: ntoskrnl/hal/x86/beep.c
|
||||
* PURPOSE: Speak support (beeping)
|
||||
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
||||
* Eric Kohl (ekohl@abo.rhein-zeitung.de)
|
||||
*/
|
||||
|
||||
/* INCLUDES *****************************************************************/
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
||||
#include <hal.h>
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
|
||||
/* CONSTANTS *****************************************************************/
|
||||
|
||||
#define TIMER2 0x42
|
||||
#define TIMER3 0x43
|
||||
#define PORT_B 0x61
|
||||
#define CLOCKFREQ 1193167
|
||||
|
||||
#define TIMER2 (PUCHAR)0x42
|
||||
#define TIMER3 (PUCHAR)0x43
|
||||
#define PORT_B (PUCHAR)0x61
|
||||
#define CLOCKFREQ 1193167
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
/*
|
||||
* FUNCTION: Beeps the speaker.
|
||||
* ARGUMENTS:
|
||||
* Frequency = If 0, the speaker will be switched off, otherwise
|
||||
* the speaker beeps with the specified frequency.
|
||||
*/
|
||||
|
||||
BOOLEAN
|
||||
STDCALL
|
||||
HalMakeBeep (
|
||||
ULONG Frequency
|
||||
)
|
||||
NTAPI
|
||||
HalMakeBeep(IN ULONG Frequency)
|
||||
{
|
||||
UCHAR b;
|
||||
ULONG flags;
|
||||
UCHAR Data;
|
||||
ULONG Divider;
|
||||
BOOLEAN Result = TRUE;
|
||||
|
||||
/* save flags and disable interrupts */
|
||||
Ki386SaveFlags(flags);
|
||||
Ki386DisableInterrupts();
|
||||
/* FIXME: Acquire CMOS Lock */
|
||||
|
||||
/* speaker off */
|
||||
b = READ_PORT_UCHAR((PUCHAR)PORT_B);
|
||||
WRITE_PORT_UCHAR((PUCHAR)PORT_B, (UCHAR)(b & 0xFC));
|
||||
/* Turn the register off */
|
||||
Data = READ_PORT_UCHAR(PORT_B);
|
||||
WRITE_PORT_UCHAR(PORT_B, Data & 0xFC);
|
||||
|
||||
/* Check if we have a frequency */
|
||||
if (Frequency)
|
||||
{
|
||||
ULONG Divider = CLOCKFREQ / Frequency;
|
||||
/* Set the divider */
|
||||
Divider = CLOCKFREQ / Frequency;
|
||||
|
||||
/* Check if it's too large */
|
||||
if (Divider > 0x10000)
|
||||
{
|
||||
/* restore flags */
|
||||
Ki386RestoreFlags(flags);
|
||||
|
||||
return FALSE;
|
||||
/* Fail */
|
||||
Result = FALSE;
|
||||
goto Cleanup;
|
||||
}
|
||||
|
||||
/* set timer divider */
|
||||
WRITE_PORT_UCHAR((PUCHAR)TIMER3, 0xB6);
|
||||
WRITE_PORT_UCHAR((PUCHAR)TIMER2, (UCHAR)(Divider & 0xFF));
|
||||
WRITE_PORT_UCHAR((PUCHAR)TIMER2, (UCHAR)((Divider>>8) & 0xFF));
|
||||
/* Set timer divider */
|
||||
WRITE_PORT_UCHAR(TIMER3, 0xB6);
|
||||
WRITE_PORT_UCHAR(TIMER2, (UCHAR)(Divider & 0xFF));
|
||||
WRITE_PORT_UCHAR(TIMER2, (UCHAR)((Divider>>8) & 0xFF));
|
||||
|
||||
/* speaker on */
|
||||
WRITE_PORT_UCHAR((PUCHAR)PORT_B, (UCHAR)(READ_PORT_UCHAR((PUCHAR)PORT_B) | 0x03));
|
||||
/* Turn speaker on */
|
||||
WRITE_PORT_UCHAR(PORT_B, READ_PORT_UCHAR(PORT_B) | 0x03);
|
||||
}
|
||||
|
||||
/* restore flags */
|
||||
Ki386RestoreFlags(flags);
|
||||
Cleanup:
|
||||
/* FIXME: Release hardware lock */
|
||||
|
||||
return TRUE;
|
||||
/* Return result */
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue