Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.0 KiB

4 years ago
  1. #ident "@(#) NEC jxbeep.c 1.2 94/10/17 11:22:04"
  2. /*++
  3. Copyright (c) 1991-1994 Microsoft Corporation
  4. Module Name:
  5. jxbeep.c
  6. Abstract:
  7. This module implements the HAL speaker "beep" routines for a MIPS
  8. system.
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. --*/
  13. #include "halp.h"
  14. #include "eisa.h"
  15. BOOLEAN
  16. HalMakeBeep(
  17. IN ULONG Frequency
  18. )
  19. /*++
  20. Routine Description:
  21. This function sets the frequency of the speaker, causing it to sound a
  22. tone. The tone will sound until the speaker is explicitly turned off,
  23. so the driver is responsible for controlling the duration of the tone.
  24. Arguments:
  25. Frequency - Supplies the frequency of the desired tone. A frequency of
  26. 0 means the speaker should be shut off.
  27. Return Value:
  28. TRUE - Operation was successful (frequency within range or zero).
  29. FALSE - Operation was unsuccessful (frequency was out of range).
  30. Current tone (if any) is unchanged.
  31. --*/
  32. {
  33. KIRQL OldIrql;
  34. NMI_STATUS NmiStatus;
  35. PEISA_CONTROL controlBase = HalpEisaControlBase;
  36. TIMER_CONTROL timerControl;
  37. ULONG newCount;
  38. BOOLEAN Result;
  39. //
  40. // Raise IRQL to dispatch level and acquire the beep spin lock.
  41. //
  42. KeAcquireSpinLock(&HalpBeepLock, &OldIrql);
  43. //
  44. // Stop the speaker.
  45. //
  46. *((PUCHAR)&NmiStatus) = READ_REGISTER_UCHAR(&controlBase->NmiStatus);
  47. NmiStatus.SpeakerGate = 0;
  48. NmiStatus.SpeakerData = 0;
  49. WRITE_REGISTER_UCHAR(&controlBase->NmiStatus, *((PUCHAR)&NmiStatus));
  50. //
  51. // If the specified frequency is zero, then the speaker is to be stopped.
  52. //
  53. if (Frequency == 0) {
  54. Result = TRUE;
  55. } else {
  56. //
  57. // If the new count has a magnitude less than 65,536 (0x10000), then
  58. // set the speaker time to the correct mode. Otherwise, return a value
  59. // of FALSE sinc ethe frequency is out of range.
  60. //
  61. newCount = TIMER_CLOCK_IN / Frequency;
  62. if (newCount >= 0x10000) {
  63. Result = FALSE;
  64. } else {
  65. //
  66. // Set the speaker timer to the correct mode.
  67. //
  68. timerControl.BcdMode = 0;
  69. timerControl.Mode = TM_SQUARE_WAVE;
  70. timerControl.SelectByte = SB_LSB_THEN_MSB;
  71. timerControl.SelectCounter = SELECT_COUNTER_2;
  72. WRITE_REGISTER_UCHAR(&controlBase->CommandMode1, *((PUCHAR) &timerControl));
  73. //
  74. // Set the speaker timer to the correct mode.
  75. //
  76. WRITE_REGISTER_UCHAR(&controlBase->SpeakerTone, (UCHAR)(newCount & 0xff));
  77. WRITE_REGISTER_UCHAR(&controlBase->SpeakerTone, (UCHAR)(newCount >> 8));
  78. //
  79. // Start the speaker.
  80. //
  81. NmiStatus.SpeakerGate = 1;
  82. NmiStatus.SpeakerData = 1;
  83. WRITE_REGISTER_UCHAR(&controlBase->NmiStatus, *((PUCHAR) &NmiStatus));
  84. Result = TRUE;
  85. }
  86. }
  87. //
  88. // Release the beep spin lock and lower IRQL to its previous value.
  89. //
  90. KeReleaseSpinLock(&HalpBeepLock, OldIrql);
  91. return Result;
  92. }