OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
ChipTune.c
Go to the documentation of this file.
1
15#include <Uefi.h>
16#include <Library/BaseMemoryLib.h>
18#include <Library/MemoryAllocationLib.h>
20#include <Library/OcMiscLib.h>
21#include <Library/OcStringLib.h>
22#include <Library/UefiApplicationEntryPoint.h>
23#include <Library/UefiBootServicesTableLib.h>
24#include <Library/UefiLib.h>
25#include <Protocol/DevicePath.h>
26#include <Protocol/AppleHda.h>
28
29EFI_STATUS
30EFIAPI
32 IN EFI_HANDLE ImageHandle,
33 IN EFI_SYSTEM_TABLE *SystemTable
34 )
35{
36 EFI_STATUS Status;
37 UINTN Argc;
38 CHAR16 **Argv;
40 APPLE_BEEP_GEN_PROTOCOL *BeepGenProtocol;
41 UINTN Count;
42 UINTN Signal;
43 UINTN Silence;
44 UINTN Frequency;
45
46 gBS->SetWatchdogTimer (0, 0, 0, NULL);
47
48 OcProvideConsoleGop (FALSE);
49
51
52 OcSetConsoleResolution (0, 0, 0, FALSE);
53
54 Status = GetArguments (&Argc, &Argv);
55 if (EFI_ERROR (Status) || (Argc < 5)) {
56 Print (L"Usage: ChipTune <any|hda|beep> <count> <signal> <silence> [<frequency>]\n");
57 return EFI_SUCCESS;
58 }
59
60 Status = StrDecimalToUintnS (Argv[2], NULL, &Count);
61 if (EFI_ERROR (Status)) {
62 Print (L"Invalid count value - %r\n", Status);
63 return EFI_SUCCESS;
64 }
65
66 Status = StrDecimalToUintnS (Argv[3], NULL, &Signal);
67 if (EFI_ERROR (Status)) {
68 Print (L"Invalid signal length value - %r\n", Status);
69 return EFI_SUCCESS;
70 }
71
72 Status = StrDecimalToUintnS (Argv[4], NULL, &Silence);
73 if (EFI_ERROR (Status)) {
74 Print (L"Invalid silence length value - %r\n", Status);
75 return EFI_SUCCESS;
76 }
77
78 if (Argc >= 6) {
79 Status = StrDecimalToUintnS (Argv[5], NULL, &Frequency);
80 if (EFI_ERROR (Status)) {
81 Print (L"Invalid frequency value - %r\n", Status);
82 return EFI_SUCCESS;
83 }
84 } else {
85 Frequency = 0;
86 }
87
88 HdaProtocol = NULL;
89 BeepGenProtocol = NULL;
90
91 if ((OcStriCmp (Argv[1], L"any") == 0) || (OcStriCmp (Argv[1], L"beep") == 0)) {
92 Status = gBS->LocateProtocol (
94 NULL,
95 (VOID **)&BeepGenProtocol
96 );
97 if (EFI_ERROR (Status) || (BeepGenProtocol->GenBeep == NULL)) {
98 Print (L"Beep protocol is unusable - %r\n", Status);
99 BeepGenProtocol = NULL;
100 }
101 }
102
103 if ((BeepGenProtocol == NULL) && ((OcStriCmp (Argv[1], L"any") == 0) || (OcStriCmp (Argv[1], L"hda") == 0))) {
104 Status = gBS->LocateProtocol (
106 NULL,
107 (VOID **)&HdaProtocol
108 );
109 if (EFI_ERROR (Status) || (HdaProtocol->PlayTone == NULL)) {
110 Print (L"HDA protocol is unusable - %r\n", Status);
111 HdaProtocol = NULL;
112 }
113 }
114
115 Print (
116 L"Trying playback %u %Lu %Lu %d\n",
117 (UINT32)Count,
118 (UINT64)Signal,
119 (UINT64)Silence,
120 (UINT64)Frequency
121 );
122
123 if (BeepGenProtocol != NULL) {
124 Status = BeepGenProtocol->GenBeep (
125 (UINT32)Count,
126 Signal,
127 Silence
128 );
129 } else if (HdaProtocol != NULL) {
130 Status = HdaProtocol->PlayTone (
131 HdaProtocol,
132 (UINT32)Count,
133 Signal,
134 Silence,
135 Frequency
136 );
137 } else {
138 Status = EFI_UNSUPPORTED;
139 }
140
141 if (EFI_ERROR (Status)) {
142 Print (L"Playback failure - %r\n", Status);
143 }
144
145 return EFI_SUCCESS;
146}
EFI_GUID gAppleBeepGenProtocolGuid
EFI_GUID gAppleHighDefinitionAudioProtocolGuid
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition ChipTune.c:31
@ EfiConsoleControlScreenText
EFI_BOOT_SERVICES * gBS
EFI_CONSOLE_CONTROL_SCREEN_MODE OcConsoleControlSetMode(IN EFI_CONSOLE_CONTROL_SCREEN_MODE Mode)
EFI_STATUS OcSetConsoleResolution(IN UINT32 Width OPTIONAL, IN UINT32 Height OPTIONAL, IN UINT32 Bpp OPTIONAL, IN BOOLEAN Force)
EFI_STATUS OcProvideConsoleGop(IN BOOLEAN Route)
Definition ConsoleGop.c:81
EFI_STATUS GetArguments(OUT UINTN *Argc, OUT CHAR16 ***Argv)
INTN EFIAPI OcStriCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
APPLE_BEEP_GEN_BEEP GenBeep
Can be NULL.
APPLE_HIGH_DEFINITION_AUDIO_PLAY_TONE PlayTone
Can be NULL.
Definition AppleHda.h:98