0

I am trying to write a C program for piano in which the node of piano is controlled by mouse movement. But as in linux #include<dos.h> and #include<conio.h> is not exist, so i am getting error . Is there any alternative library present in linux for #include<conio.h> and #include<dos.h> ? I have tried the code following.

#include <dos.h>
#include <graphics.h>
union REGS in, out;

void detect_mouse ()
{
    in.x.ax = 0;
    int86 (0X33,&in,&out);   //invoke interrupt
    if (out.x.ax == 0)
        printf ("\nMouse Failed To Initialize");
    else
        printf ("\nMouse was Succesfully Initialized");
}

void showmouse_graphics ()
{
    int gdriver = DETECT, gmode, errorcode;
    initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
    in.x.ax = 1;
    int86 (0X33,&in,&out);
    getch ();
    closegraph ();
}
void detect ()
{
    int button;
    while (!kbhit () )
    {
        in.x.ax = 3;
        int86 (0X33,&in,&out);
        button=out.x.bx&7
        switch(button)
        {
            case 1:
                print(“left button pressed\n”);
            break;
            case 2:
                print(“right button pressed\n”);
            break;
            case 4:
                print(“middle button pressed\n”);
            break;
            case 3:
                print(“left and right button pressed\n”);
            break;
            case 5:
                print(“left and middle button pressed\n”);
            break;
            case 6:
                print(“right and middle button pressed\n”);
            break;
            case 7:
                print(“all the three buttons pressed\n”);
            break;
            default:
                print(“No button pressed\n”);
        }
        delay (200); // Otherwise due to quick computer response 100s of words will get print
    }
}
void hide_mouse ()
{
    in.x.ax = 2;
    int86 (0X33,&in,&out);
}

int main ()
{
    detect_mouse ();
    showmouse_graphics ();
    detect ();
    hide_mouse ();
    return 0;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 3
    That is ancient Borland Turbo C code shown, these days you can't use graphics like that unless you have a simulator to run it in. The old DOS interrupts won't work either, outside of a simulator, because Linux is not MS-DOS. You might consider using `termios`, please see [Mouse event handling in Linux?](https://stackoverflow.com/questions/52233626/mouse-event-handling-in-linux) – Weather Vane Jun 23 '20 at 12:46

1 Answers1

3

For #include<conio.h> you can use #include <curses.h> which will give you almost all the functionalities. Getchar

For #include<dos.h> it's not usable in any other operating system than DOS and there isn't really something similar with all the functionalities in linux. But you can use usleep(microseconds) in linux when you include #include <unistd.h>.

Or you can use sleep_for in c++:

using namespace std::this_thread; // sleep_for, sleep_until
using namespace std::chrono; // nanoseconds, system_clock, seconds
sleep_for(nanoseconds(20));

For Generating Sound, it seems that this post tries to do something similar/could help with your problem:

Generate Sound Frequency using GCC

IndieGameDev
  • 2,905
  • 3
  • 16
  • 29
  • #include is needed for sound generation in piano. is there any alternative function which can generate the sound in linux? there is several function like interrupt function int86 (0X33,&in,&out) will not work except #include . How to resolve that kindly help me –  Jun 23 '20 at 12:31