[SOLVED] PC speaker does not work

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Klakap
Member
Member
Posts: 299
Joined: Sat Mar 10, 2018 10:16 am

[SOLVED] PC speaker does not work

Post by Klakap »

Good day!
I tried to play sound from the PC speaker code:
BITS 16

Code: Select all

start:
mov ax, 07C0h ; Set 4K stack space after this bootloader
add ax,, 288 ; (4096 + 512) / 16 apartments under paragraph
mov ss, ax
mov sp, 4096

mov ax, 07C0h ; Set data segment to where we're loaded
mov ds, ax

mov ax, 1000
call os_speaker_tone

jmp $

os_speaker_tone:
pusha

mov cx, ax ; Store note value now

mov al, 182
out 43h, al
mov ax, cx ; Set the frequency
out 42h, al
mov al, ah
out 42h, al

in al, 61 h ; Switch PC speaker
or al, 03h
of the 61 h, al

popa
ret
(This is a function of MikeOS.) But the sound does not work. When I run MikeOS, so sound worked. Please what do I do?
Last edited by Klakap on Sat Apr 14, 2018 8:24 am, edited 1 time in total.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: PC speaker does not work

Post by iansjack »

Silly question, but - does your computer actually have a speaker (connected)?
Klakap
Member
Member
Posts: 299
Joined: Sat Mar 10, 2018 10:16 am

Re: PC speaker does not work

Post by Klakap »

As far as I know, in the MikeOS PC speaker does not connect and the sound works. But when I copied the method from MikeOS that plays sound(os_speaker_tone) so after call his, I didn't get result!
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: PC speaker does not work

Post by iansjack »

You didn't answer my silly question.

Never mind.
Klakap
Member
Member
Posts: 299
Joined: Sat Mar 10, 2018 10:16 am

Re: PC speaker does not work

Post by Klakap »

MikeOS and my OS I run through qemu. I don't know whether it is in qemu a Pc speaker connected or not.
Klakap
Member
Member
Posts: 299
Joined: Sat Mar 10, 2018 10:16 am

Re: PC speaker does not work

Post by Klakap »

I already found the problem, it was sufficient to run the kernel:
qemu-system-i386 -soundhw pcspk -kernel kernel
PC speaker works!
Post Reply