Solved

Linux Registers

Posted on 1997-03-30
1
639 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to calculate times for developing software? 8 67
Folder Comparison 12 54
Not needed 13 112
Is there a simple front-end menu system. 9 89
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.

809 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