#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <iostream.h>
#include <stdlib.h>

const long clock = 1193180;

int main(){
	int a = 0;
	char notes[10][3] = { "Do-diez","Sol","Re" };
	int i;
	float length[3] = { 5, 1, 3 };
	int note[3] = { 277, 392, 293 };
	
	system("cls");
	printf("Playing sound using timer. Press any key to continue...\n");
	getch();
	outportb(0x43, 0xB6);
	outportb(0x61, inportb(0x61) | 3);
	//...11
	for (i = 0; i<3; i++) {
		outportb(0x42, (clock / note[i]) & 0x00FF);
		outportb(0x42, (clock / note[i]) >> 8);
		printf("Played note %s\n", notes[i]);
		delay(length[i] * 1000);
	}
	outportb(0x61,inportb(0x61)&0xfc);
	//...00
	
	printf("Playing sound without timer. Press any key to continue...\n");
	getch();
	for(i=0; i <3; i++){
		outportb(0x61,inportb(0x61)|2); 
		//...10
		delay(length[i] * 1000);
		printf("Played sound\n");
		outportb(0x61,inportb(0x61)^2); 
		//...00
		printf("End note\n");
	}

	system("pause");
	return 0;
}