Category : C Source Code
Archive   : CBIBLE.ZIP
Filename : OUTPORTB.C

 
Output of file : OUTPORTB.C contained in archive : CBIBLE.ZIP
/* outportb.c --- p 525 */
#include
#include
#define TIMER_FREQ 1193180L /* Timer freq = 1.19 MHz */
#define TIMER_COUNT 0x42 /* 8253 timer -- count */
#define TIMER_MODE 0x43 /* 8253 timer control port */
#define TIMER_OSC 0xb6 /*To use timer as oscillator */
#define OUT_8255 0x61 /* 8255 PPI output port adrs */
#define SPKRON 3 /* Bit 0 = control spkr by timer*/
/* Bit 1 = speaker on/off */
main()
{
unsigned freq, status, ratio, part_ratio;
char input[81];
cprintf("Enter frequency in Hz (between 100 and 15000):");
cscanf("%hu", &freq);
/* First read and save status of the 8255 chip */
status = inportb (OUT_8255);
/* Put timer in oscillator mode */
outportb (TIMER_MODE, TIMER_OSC);
ratio = (unsigned)(TIMER_FREQ/freq);
part_ratio = ratio & 0xff; /* low byte of ratio */
outportb(TIMER_COUNT, part_ratio);
part_ratio = (ratio >> 8) & 0xff; /* high byte */
outportb(TIMER_COUNT, part_ratio);
/* Finally turn on speaker */
outportb (OUT_8255, (status : SPKRON));
/* Ask user to indicate when to stop the
* annoying tone... */
cprintf("\nHit return to exit:");
cgets(input);
/* Now turn off speaker */
status = inportb (OUT_8255); /* get current status */
/* Turn speaker off */
outportb (OUT_8255, (status & ~SPKRON));
}

  3 Responses to “Category : C Source Code
Archive   : CBIBLE.ZIP
Filename : OUTPORTB.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/