Solved

Linux Registers

Posted on 1997-03-30
1
643 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 98
Expand macro to ask for filename column 8 37
Prevent this page from creating additional dialogs. 3 720
withoutTen challenge 14 137
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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