Solved

Linux Registers

Posted on 1997-03-30
1
636 Views
Last Modified: 2013-12-26
I have the following code sample from a DOS program I wrote.  I would like to port the program to Linux, but I don't know how to reach the registers without dos.h  The code also uses int86() which I don't think is usable within Linux.  I am looking for a replacement for the following member function:

// The purpose of the function is to return a key value only if a key
//is hit, otherwise return 0. It does NOT wait for a key to be pressed

int Fractal::GetKey ()
{
  union REGS r;            // Gain access to the registers
  if (!kbhit ())            // Return if no key pressed
       return 0;
  r.h.ah = 0;
  int86 (0x16, &r, &r);      // Get scancode of key
  if (!r.h.al)
    return (r.h.ah | 128);
 return (r.h.al & 255);      // Return the key number
}
0
Comment
Question by:wiggin
1 Comment
 
LVL 4

Accepted Solution

by:
jos010697 earned 100 total points
ID: 1292480
It doesn't work that way if you're using a Unix variant. Have
a look at your manual pages for ioctl(). It's purpose is to
set characteristics of an IO device. Something along the
following lines should do the job (check it out, I haven't
tested it)

int GetKey()
{
struct sgttyb tty, tty_org;
char           key;
int            retval;

/* get and save tty settings */
ioctl(fileno(stdin), TIOCGETP, &tty_org);
tty = tty_org;

/* set terminal to raw mode, no echo, no nothing */
tty.sg_flags |= CRMOD;
tty.sg_flags &= ~ECHO;
tty.sg_flags &= ~XTABS;

/* could be: tty.sg_flags |= CBREAK; */
tty.sg_flags |= RAW;
ioctl(0, TIOCSETP, &tty);
fcntl(0, F_SETFL, O_NDELAY);

/* read a keystroke */
if ((retval= read(0, &key, 1)) == 1)
        retval= key;

/* restore terminal settings */
ioctl(fileno(stdin), TIOCSETP, &tty_org);
fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0)&~O_NDELAY);

return retval;
}

kind regards,

Jos
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 84
tripleUp challenge 7 74
pre4 challenge 19 94
matchUp  challenge 9 94
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now