I want to halt the execution about 0.1 seconds, regardless of the clock speed of the CPU. The code should run directly from a boot device, it should therefore not use DOS interrupts.
I'm currently using int 15h
, but this seems to conflict with the beep tones I'm modulating with channel 2 of the PIT. I heard of channel 0, but I have no clue about how to set this up.
The accuracy is not that important, however, it should run on old and modern computers at the same speed. So just looping instructions is not an option.
The beep code and the sleep are just a bunch of macros for changing the frequency and turning the speaker on and off. The beep seems to not stop if I call sleep right before beepoff
.
Here are the beep macros:
%macro beepinit 0
mov al, 182
out 43h, al
%endmacro
%macro beepfreq 0
out 42h, al
mov al, ah
out 42h, al
%endmacro
%macro beepon 0
in al, 61h
or al, 00000011b
out 61h, al
%endmacro
%macro beepoff 0
in al, 61h
and al, 11111100b
out 61h, al
%endmacro
and the sleep one:
%macro sleep 2
push dx
mov ah, 86h
mov cx, %1
mov dx, %2
int 15h
pop dx
%endmacro
I'm using the NASM assembler.
This is not a duplicate of How can I create a sleep function in 16bit MASM Assembly x86?, because this one is for bare-metal assembly outside of Windows or DOS.