Does anyone know where to return a code to Linux. I know this is so much simpler than it seems. In Dos...

MOV AH,09
INT 21
MOV AH,4C
INT 21

Just grabs a key and calls exit with return, but for some reason I cant' seem to to the same on a LINUX system.
Thanks for any help
:shock:
Posted on 2007-04-05 10:03:44 by Jeronimo0d0a
Assuming you know that Linux is, at least, a 32-bit Protected Mode operating system that operates using the standard *nix system interrupt call of 0x80 (INT 0x80)...

getch is MS-specific stuff. AFAIK, LibC calls it "getchar".
Posted on 2007-04-05 11:23:33 by SpooK
There is no system call for 'getchar'.  All input comes from stdin which is probably the keyboard in your case.  So a system call has to go to 'read' or 'sys_read' whatever they call it in Linux.  There should be a file called syscalls.h that lists all system calls.
Posted on 2007-04-07 10:19:41 by drhowarddrfine
This is way stale, but doesn't seem to have an answer. Perhaps I should start a new thread, but... same topic...

Jeronimo0's dos code is incorrect, but that's okay - we know what you mean. Also incorrect is "simpler than it seems". Actually it's a real PITA - at least, I don't know an easy way to do it.

The issue is... yes, we have to use sys_read (or something that uses it). On STDIN, sys_read doesn't return until 'enter' is hit. So "press any key to continue" has to be "press any key as long as it's 'enter'...". I, for one, would like to be able to get "just one key", as you can easily do with dos/bios!

It is possible to alter the behavior of sys_read on STDIN via sys_ioctl. One way to proceed is to set up STDIN to return when a key is hit, do your program, and clean up your mess before exiting (you can leave STDIN in such a state that bash can't cope - try a new console... "login:"... and as soon as you hit one key, "invalid login"!!! A real mess, so don't.)

But I'd like to be able to use STDIN normally to get a string, in between calls to "just one key, please". So I've been fiddling with a subroutine which calls  sys_ioctl/TC_GETS to get a "termios" structure, alters the structure, sys_ioctl/TC_SETS, gets my one key with sys_read, alters the termios structure back to "normal", sys_ioctl/TC_SETS again, and finally returns the key (in al, of course). This is a lot of code, and a lot of system calls, to get just one key!!!

It's good enough for "toy" programs, but it's not done yet. In the first place, I ASSume that STDIN was "normal" when I got it. I should use two termios buffers, do TC_GETS into one, copy it to the other (I've seen code that calls sys_ioctl/TC_GETS twice... more system calls!), alter the copy, TC_SETS from the copy, get my key, and TC_SETS from the original, not my ASSumption. That's easily fixed, I've just been lazy.

More serious, I really should be catching some "signals". For example, if the program is suspended (while waiting for a key - when else?) with cntl-z, and restored with "fg", I'm back in "any key as long as it's 'enter'" mode. I can live with it, but it's not "right". I think SIGWINCH messes it up, too. I don't know much about "signals", so I'm not sure how to fix this. (anyone?)

I don't, as yet, do anything with "extended" keys - arrow keys, function keys, etc. These generate multiple bytes, beginning with ESC (1Bh), which I think I can handle, but... what to return? I guess do it like a bios interrupt - 0 in al, and a keycode in ah? Or like a dos interrupt - call it again? Dunno...

In any case, if anyone's interested in fooling with this, I can post my "work in progress". I think it's a "Good Question"!

Best,
Frank

Posted on 2009-11-03 07:23:24 by fbkotler