Solved

Linux Registers

Posted on 1997-03-30
1
634 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 83
Get filename and folder into excel 7 67
Whole sheet autoscrub still needed 19 44
isEverywhere  challenge 19 64
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‚Ķ
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video discusses moving either the default database or any database to a new volume.

743 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

16 Experts available now in Live!

Get 1:1 Help Now