Beep Sound Through Batch

Beep Sound through Batch
by Jakash3
September 26, 2010

Ok, so here’s something simple that I would like to share with you.
In this batch file, we will make the computer beep. In order to do
that, we will assemble a com file through debug.exe which will print
the bell character (0x07) for us. Keep in mind that debug.exe is a
16-bit program, which means it only works on either MS-DOS or a
32-bit version of Windows (since it contains ntvdm for virtually
running 16-bit programs).

Let’s start with the simple example that will utilize the MS-DOS
API interrupt for outputting the character:

@echo off
echo a
echo mov ah,2
echo mov dl,7
echo int 21
echo int 20
echo r cx
echo 8
echo n
echo w
echo q
del mkbell.dbg
echo BEEP!

So first of all, we output some code to a file that will act like a
script for debug.exe. Sub-command ‘a’ will enter the assembly-mode
prompt in debug, then we input our asm code to print the bell
character. We do this by using the sub-function 2 (print character)
in the 21st interrupt with parameter of character to print placed in
register DL. Then we execute the function call with ‘int 21’. Then
we terminate the program with ‘int 20’.

To create the com file, we use the ‘w’ sub-command to output as many
bytes loaded into debug’s memory as the value of debug’s CX register.

So before we do that, we set debug’s CX register with ‘r cx’ to 8
since our code is 8 bytes long. Then we set the output filename with
the ‘n’ sub-command to ‘’. ‘w’ to output to file, and ‘q’ to
quit debug.

‘debug<mkbell.dbg>nul’, we start debug with that script for it to
automatically assemble our file. Then we delete the script file and
finally start our com file to print the character. And that’s it.

An alternative to this is just to use debug to output the bell
character to a file, and then use the TYPE command to print that file
to produce a ring:

@echo off
echo e 0 7
echo r cx
echo 1
echo n bell
echo w
echo q
del mkbell.dbg
echo BEEP!
type bell
del bell

10 thoughts on “Beep Sound Through Batch

    • I believe so but I haven’t tried it. There’s a sound api called SoundBlaster, found under int 80h. DOSBox says it supports SoundBlaster api under it’s dos emulator. One of the functions is int 80h/bx=6 which is used to “play music” where dx:ax points to the “music block”; but it’s a mystery to me how this music block is formatted.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: