Small x86-16 beep in QEMU

398 Views Asked by At

I am creating a small pong game using x86-16 assembly in a boot sector to run in QEMU on Ubuntu 20.04.2.
I want to make a console beep when the ball hits a paddle. What would be a space efficient way to create a beep sound of any kind in x86-16?

I'm using FASM.

1

There are 1 best solutions below

0
Sep Roland On

You can use the BIOS.Teletype function 0Eh for this.

It's a function that writes the character from AL to the display page from BH using the color from BL. The function also interprets some control codes: 13 for carriage return, 10 for linefeed, 8 for backspace, and 7 for bell. The function returns nothing.

Because sounding the beeper is an audible operation, you can shave off a few bytes and not mention anything for the displaypage or the color.

In the limited space of your bootsector, next is all it takes to beep:

mov ax, 0E07h  ; BIOS.Teletype BELL
int 10h