2

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.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
Frundok
  • 21
  • 1
  • 2
    https://stackoverflow.com/questions/29714604/make-beep-sound-in-bios is somewhat relevant, though it's for inline asm. What makes this awkward is that the hardware commands just turn the beeper on and off, so you have to create your own delay in between - either by busy wait, or by hooking a timer interrupt. – Nate Eldredge Jul 20 '21 at 07:12
  • 1
    @NateEldredge OP could hook the timer IRQ, set it to one-shot and use that to turn off the beep. – fuz Jul 20 '21 at 07:26
  • 3
    If you're not fussy (pitch, duration); you could try printing an ASCII "bell" character using the BIOS. – Brendan Jul 20 '21 at 09:42
  • @Brendan If the game logic is triggered by timer tick, that might even work. – fuz Jul 20 '21 at 10:10
  • @Brendan yeah that should work, not sure how to go about that in x86-16 though, that's pretty much what the question is; elaborate? – Frundok Jul 20 '21 at 12:01
  • @Frundok: Maybe like `mov ax,(0x0E << 8) | 0x07`, `mov bh, something` then `int 0x10`. In this case `bh` is supposed to be "display page number" (probably zero but depends on how you're doing graphics). – Brendan Jul 20 '21 at 14:21

1 Answers1

1

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
Sep Roland
  • 33,889
  • 7
  • 43
  • 76