You are on page 1of 6

CLASS XI C.Sc. Proj.

DOS-Tones 1.0.0
C.Sc. Turbo C++ Project

By : Tushant Jha, Utkarsh Sharma, Palash Gupta, Aditya Tiwari

Synopsis

The DOS-Tones project is a project on the 'language of old times', that is Turbo
C++. It uses BGI graphics and Mouse.h, calling mouse interrupts, to provide
DOS Graphical Interface as the user-interface. Its basic function is that the user
can fix musical notes, and hear the CPU Beep Music. Although this is of no
practical use today as there are already softwares available, which are million-
times useful than this, but the project atleast helps us go back into the ancestry of
softwares like Fruity Loops and Audacity and understand their working.

Source Code

/*DOS-Tones 1.0.0
(C) Tushant Jha, Utkarsh Sharma, Palash Gupta, Aditya Tiwari*/

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<iostream.h>

1
DOS-Tones 1.0.0
#include<mouse.h>

int x=120,y=20,s=40,xmax,ymax;
char notes[50],notesbkup[50];
char key;
void display();

void welcome() //the welcome screen in DOS Shell


{
cout<<"We know this isn't going to be fun, but the culprits are not the
programmers, the limitations of Turbo C++ are to be blamed";
delay(5000);
clrscr();
gotoxy(11,12);
cout<<"DOS-Tones 1.0.0";
delay(5000);
}

char up(char inp) //to increase a note


{
char tj;
switch(inp)
{
case 'O':tj= 'C';break;
case 'C':tj= 'c';break;
case 'c':tj= 'D';break;
case 'D':tj= 'd';break;
case 'd':tj= 'E';break;
case 'E':tj= 'F';break;
case 'F':tj= 'f';break;
case 'f':tj= 'G';break;
case 'G':tj= 'g';break;
case 'g':tj= 'A';break;
case 'A':tj= 'a';break;
case 'a':tj= 'B';break;
case 'B':tj= 'O';break;
}
return tj;
}

void playnote(char nt)


{
switch(nt)
{
case 'C':sound(261);delay(500);nosound();break;
case 'c':sound(277);delay(500);nosound();break;
case 'D':sound(293);delay(500);nosound();break;
case 'd':sound(311);delay(500);nosound();break;
case 'E':sound(329);delay(500);nosound();break;
case 'F':sound(349);delay(500);nosound();break;
case 'f':sound(370);delay(500);nosound();break;
case 'G':sound(392);delay(500);nosound();break;
case 'g':sound(415);delay(500);nosound();break;
case 'A':sound(440);delay(500);nosound();break;
case 'a':sound(466);delay(500);nosound();break;
case 'B':sound(494);delay(500);nosound();break;
case 'O':delay(500);break;
}

2
DOS-Tones 1.0.0
}

void playfull()
{
mousehide();
for(int i=0;i<50;i++)
{
notesbkup[i]=notes[i];
playnote(notes[i]);
notes[i]=notesbkup[i];
}
mouseshow();
display();
}

void display()
{
clearviewport();
rectangle(10,10,630,470);
settextstyle(0,0,3);
outtextxy(140,360,"DOS-Tones 1.0.0");
settextstyle(0,0,1);
outtextxy(80, 450, "By Tushant Jha, Utkarsh Sharma, Palash Gupta, Aditya
Tiwari");
settextstyle(0,0,0);
rectangle(60,280,120,310);
outtextxy(73,292,"PLAY");
rectangle(520,280,580,310);
outtextxy(533,292,"EXIT");
char *g, h;
for(int i=0;i<5;i++)
{
for (int j=0;j<10;j++)
{
int m=x+(j*s)+(s/2),n=y+(i*s)+(s/2);
h=notes[(10*i)+j];
sprintf(g,"%c",h);
rectangle (x+(j*s),y+(i*s),x+s+(j*s),y+s+(i*s));
outtextxy(m,n," ");
outtextxy(m,n,g);
}
}
}

void refresh() //to refresh my array containing notes


{
for(int i=0;i<50;i++)
{
notes[i]='O';
}
}

void main()
{
clrscr();
refresh();
welcome();
int gd=DETECT,gm,exit=0,mx,my,click,nx,ny,p;

3
DOS-Tones 1.0.0
initgraph(&gd, &gm, "c:/tc/bgi ");
xmax=getmaxx();
ymax=getmaxy();
setcolor(1);
setbkcolor(11);
setfillstyle(0,1);
mouseshow();
display();
do //the most important loop of program
{
mouseposi(mx,my,click);
if(click==1)
{
delay(500);
if(((mx>x)&&(mx<(x+(30*s))))&&((my>y)&&(my<(y+(10*s)))))
{
nx=(mx-x)/s;
ny=(my-y)/s;
p=(10*ny)+nx;
notes[p]=up(notes[p]);
display();
}
if(((mx>520)&&(mx<580))&&((my>280)&&(my<310)))
{
exit=1;
}
if(((mx>60)&&(mx<120))&&((my>280)&&(my<310)))
{
playfull();
}
}
}while(exit==0); //loops indefinitely until exit is 1, as to be done by exit button
closegraph();
clrscr();
cout<<"Thanks for bearing such a rubbish project";
getch();
}

1. welcome() & refresh()

The welcome() function simply uses gotoxy & cout functions to get a simple welcome screen.

The refresh() function just initiates all the values in notes[50] array to 'O'.

The values in notes[50] array represent the musical notes to be played.

2. up(inp) , playnote(nt) & playfull()

These functions are all related to music. The up(inp) function returns the next piano note of
the note passed into the function.

The playnote(nt) function uses the functions sound(frequency), delay(time), & nosound() to
make beeps corresponding to different piano notes from the CPU. The playfull() function uses

4
DOS-Tones 1.0.0
playnote to play the whole array notes. A backup array is kept as the array pointers show
anomalous behaviour after playnote treats them as integers (as single chars are ints).

3. display()

This function sets the screen as required. It uses a for loop to precisely place a table of notes
with the corresponding values in array printed with it. It is used very frequently, as it doesn't
even slow down the program, whenever the array is altered.
It uses functions such as rectangle, settextstyle, outtextxy, & clearviewport, all graphics
functions defined in graphics.h, a native library in Turbo C++.
Also sprintf had to be used as outtextxy can take only string values, while array always points
to single-character, which are stored as integers (ASCII).

4. mouse.h

union REGS in,out; //for accessing the AX register (mouse


register)

void mouseshow() //displays mouse pointer


{
in.x.ax=1;
int86(51,&in,&out); //used to read in/out of the register
}

void mousehide() //hides mouse pointer


{
in.x.ax=2;
int86(51,&in,&out);
}

void mouseposi(int &xpos, int &ypos, int &click)


{ //for getting current coordinates and click status of mouse
in.x.ax=3;
int86(51,&in,&out);
click=out.x.bx;
xpos=out.x.cx;
ypos=out.x.dx;
}

void setposi(int &xpos, int &ypos) //sets mouse pointer to given coordinates
{
in.x.ax=4;
in.x.cx=xpos;
in.x.dx=ypos;
int86(51,&in,&out);
}

This header file calls interrupts from mouse driver to allow use of mouse in dos shell.

5
DOS-Tones 1.0.0
5. main()

The initial part of main() function does the basic work by calling clrscr(), refresh(),
welcome(), initializing the graph, setbkcolor(), and mouseshow(). The it calls display() for
first time during execution.

The do-while loop that follow initialization is the most important part of program. As we
declare a variable 'exit', we initialize it as 0, and the loop runs indefinitely as long as exit
has value 0. Inside the loop, we call mouseposi() to get the status of mouse, and if it has
been clicked we check if it has been clicked at a point where it 'should' be clicked.
Depending on where it is clicked, respective functions are performed. If the click was
inside the table, then a Modular-Row-Column Algorithm is used to 'up' the value in
array which corresponds to the clicked cell. If the 'play' button is clicked, playfull() is
called, and if 'exit' is clicked, the value of int variable 'exit' becomes 1. As 'exit' becomes
1, the loop stops 'looping', thus coming out to 'The End' message.

6
DOS-Tones 1.0.0

You might also like