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
Solved

Linux Registers

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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
ffmpeg - "rtsp://...... Operation not permitted" 4 86
Detect file exist or not 3 178
Trying to run powershell  in a batch file. How do I do this? 8 105
Making an alias 7 101
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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 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