try this....Moonie
you might need to use -DUSE_WIN32 or -DUSE_DOS or -DUSE_LINUX
and if using win32 to include windows and use dos to include dos.h an
i believe i have include the right headers for linux..off topic o
course. you can scream at my programming later.
#include <time.h>
void DELAY( int msec )
{ clock_t goal;
goal = (clock_t) msec + clock();
while ( goal > clock() );
}
#if defined(USE_WIN 32)
void DoSound( unsigned int freq, unsigned int time )
{
Beep( freq, time );
return;
}
#elif defined(USE_DOS )
#if defined(__DJGPP __)
#undef nosound
void nosound(void)
{
sound(0);
return;
}
void DoSound(unsigne d int freq, unsigned int time)
{
sound(freq);
DELAY(time);
nosound();
return;
}
#elif defined(HAVE_SO UND)
void DoSound(unsigne d int freq, unsigned int time)
{
sound(freq);
DELAY(time);
nosound();
return;
}
#else
#ifndef LOBYTE
#define LOBYTE(w) ((BYTE) (w))
#endif
#ifndef HIBYTE
#define HIBYTE(w) ((BYTE) (((USHORT) (w) >> 8) & 0xFF))
#endif
EXTERN void HWSound( unsigned );
EXTERN void HWNoSound( void );
void HWSound(unsigne d int freq)
{
USHORT counter = 1193280 / freq; /* cycle counter */
outp(0x43, 0xB6); /* prepare timer */
outp(0x42, LOBYTE(counter) ); /* send low byte */
outp(0x42, HIBYTE(counter) ); /* send high byte */
outp(0x61, inp(0x61) | 0x03); /* turn speaker ON */
return;
}
void HWNoSound(void)
{
outp(0x61, inp(0x61) & 0xFC); /* turn speaker OFF */
return;
}
void DoSound(unsigne d int freq, unsigned int time)
{
HWSound(freq);
DELAY(time);
HWNoSound();
return;
}
#endif
#else
#include <asm/io.h>
#include <signal.h>
#include <stdio.h>
#define outp outb
#define inp inb
#ifndef LOBYTE
#define LOBYTE(w) ((BYTE) (w))
#endif
#ifndef HIBYTE
#define HIBYTE(w) ((BYTE) (((USHORT) (w) >> 8) & 0xFF))
#endif
EXTERN void HWSound( unsigned );
EXTERN void HWNoSound( void );
void HWSound(unsigne d int freq)
{
USHORT counter = 1193280 / freq; /* cycle counter */
outp(0x43, 0xB6); /* prepare timer */
outp(0x42, LOBYTE(counter) ); /* send low byte */
outp(0x42, HIBYTE(counter) ); /* send high byte */
outp(0x61, inp(0x61) | 0x03); /* turn speaker ON */
return;
}
void HWNoSound(void)
{
outp(0x61, inp(0x61) & 0xFC); /* turn speaker OFF */
return;
}
void DoSound(unsigne d int freq, unsigned int time)
{
HWSound(freq);
DELAY(time);
HWNoSound();
return;
}
#endi
-
Mooni
-----------------------------------------------------------------------
Posted via
http://www.codecomments.co
-----------------------------------------------------------------------