Author: ion
Date: Mon Nov 13 07:34:57 2006
New Revision: 24742
URL:
http://svn.reactos.org/svn/reactos?rev=24742&view=rev
Log:
- Make HalMakeBeep a bit nicer by making the PUCHAR typedef part of the TIMER constants.
Modified:
trunk/reactos/hal/halx86/generic/beep.c
Modified: trunk/reactos/hal/halx86/generic/beep.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/hal/halx86/generic/beep.c?…
==============================================================================
--- trunk/reactos/hal/halx86/generic/beep.c (original)
+++ trunk/reactos/hal/halx86/generic/beep.c Mon Nov 13 07:34:57 2006
@@ -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(a)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(a)reactos.org)
+* Eric Kohl (ekohl(a)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;
-
- /* save flags and disable interrupts */
- Ki386SaveFlags(flags);
- Ki386DisableInterrupts();
+ UCHAR Data;
+ ULONG Divider;
+ BOOLEAN Result = TRUE;
- /* speaker off */
- b = READ_PORT_UCHAR((PUCHAR)PORT_B);
- WRITE_PORT_UCHAR((PUCHAR)PORT_B, (UCHAR)(b & 0xFC));
+ /* FIXME: Acquire CMOS Lock */
+ /* 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;
}