Page 1 of 1

vmWare and pc speaker

Posted: Tue Aug 18, 2009 8:18 pm
by jeandaniel
Hello,
I have created a C++ micro Kernel for a school project. I used vmware on a Suse Laptop. . Last year, i used the same laptop on a Suse distrib and the speaker worked fine.

And now The kernel works but not the pc speaker ( I have just the same bip for each note)
Any Idea ?

Code: Select all

Speaker::Speaker()
{
	initialize = false;
	init();
}

Speaker::~Speaker()
{
	initialize = true;
	close();
}

void Speaker::close()
{
	if(initialize)
	{
		outb(0x61, inb(0x61) & 252); // close speaker	
		initialize = false;
	}
}

void Speaker::init()
{
	if(!initialize)
	{
		listUsed = false;
		outb(0x61, inb(0x61) | 3); // enable speaker
		outb(0x43, 0xb6); // program the pit
		initialize = true;
	}
}

void Speaker::playMarseillaise()
{
	init();
	asm("cli");
	int counter = (0x1234DD / RE); // calculate frequency
	outb(0x42, counter & 0xff); // LSB
	outb(0x42, counter >> 8); // MSB
	wait(800);
	counter = (0x1234DD / RE); // calculate frequency
	outb(0x42, counter & 0xff); // LSB
	outb(0x42, counter >> 8); // MSB
	wait(800);
	counter = (0x1234DD / SOL); // calculate frequency
	outb(0x42, counter & 0xff); // LSB
	outb(0x42, counter >> 8); // MSB
	wait(1000);
	counter = (0x1234DD / SOL); // calculate frequency
	outb(0x42, counter & 0xff); // LSB
	outb(0x42, counter >> 8); // MSB
	wait(800);
	counter = (0x1234DD / LA); // calculate frequency
	outb(0x42, counter & 0xff); // LSB
	outb(0x42, counter >> 8); // MSB
	wait(800);
	counter = (0x1234DD / LA); // calculate frequency
	outb(0x42, counter & 0xff); // LSB
	outb(0x42, counter >> 8); // MSB
	wait(800);
	counter = (0x1234DD / 587); // calculate frequency
	outb(0x42, counter & 0xff); // LSB
	outb(0x42, counter >> 8); // MSB
	wait(1000);
	counter = (0x1234DD / SI); // calculate frequency
	outb(0x42, counter & 0xff); // LSB
	outb(0x42, counter >> 8); // MSB
	wait(400);
	counter = (0x1234DD / SOL); // calculate frequency
	outb(0x42, counter & 0xff); // LSB
	outb(0x42, counter >> 8); // MSB
	wait(800);
	__asm("cli");
	close();
}


Re: vmWare and pc speaker

Posted: Tue Aug 18, 2009 9:02 pm
by alethiophile
Well, this can't be right:

Code: Select all

   init();
   asm("cli");
   (lots of code)
   __asm("cli");
   close();
Shouldn't the second one be 'sti'? And why do you use asm for one, and __asm for the other?

Re: vmWare and pc speaker

Posted: Tue Aug 18, 2009 10:22 pm
by earlz
What does your wait function look like? does it include a STI and CLI?