简体   繁体   中英

Make beep sound in BIOS

When computer starts to boot, It makes a beep sound from the BIOS Speaker .

How do i can do this in Assembly or C++ ? Clearly I want to make Beep Sound by BIOS Speaker.
Remember i mean BIOS Speakers

Does it have any interrupt for that ? I searched about that but nothing found.. I used some interrupt But the didn't do this. the following code :

int main(){
   cout<<"\a";
}

Produced the sound from the Speaker, Not Bios

How can i do this ? with any interrupt ?

Try to add this code, too.

.pause1:
    mov     cx, 65535
.pause2:
    dec     cx
    jne     .pause2
    dec     bx
    jne     .pause1
    in      al, 61h         ; Turn off note (get value from
                            ;  port 61h).
    and     al, 11111100b   ; Reset bits 1 and 0.
    out     61h, al         ; Send new value.

So, the result is:

void beep(){

    __asm{

      MOV al, 182         ; Prepare the speaker for the
      out     43h, al     ;  note.
      mov     ax, 2280    ; Frequency number (in decimal)
                          ;  for C.
      out     42h, al     ; Output low byte.
      mov     al, ah      ; Output high byte.
      out     42h, al 
      in      al, 61h     ; Turn on note (get value from
                          ;  port 61h).
      or      al, 00000011b   ; Set bits 1 and 0.
      out     61h, al         ; Send new value.
      mov     bx, 4       ; Pause for duration of note.


    .pause1:
       mov     cx, 65535
    .pause2:
       dec     cx
       jne     .pause2
       dec     bx
       jne     .pause1
       in      al, 61h         ; Turn off note (get value from
                               ;  port 61h).
       and     al, 11111100b   ; Reset bits 1 and 0.
       out     61h, al         ; Send new value.

   };
}

The only way you can implement this in any modern Windows OS is, I guess, writing Kernel Mode driver. The reason is that in or out instructions are not available in user mode, and there is no API for beeper available.

However, if you're just willing to dig into low-level programming, consider writing own bootloader or even own BIOS (using virtual machine).

Try to include this procedure in your C++ program.

void beep(){

    __asm{

      MOV al, 182         ; Prepare the speaker for the
      out     43h, al     ;  note.
      mov     ax, 2280    ; Frequency number (in decimal)
                          ;  for C.
      out     42h, al     ; Output low byte.
      mov     al, ah      ; Output high byte.
      out     42h, al 
      in      al, 61h     ; Turn on note (get value from
                          ;  port 61h).
      or      al, 00000011b   ; Set bits 1 and 0.
      out     61h, al         ; Send new value.
      mov     bx, 4       ; Pause for duration of note.
   };
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM