Tech Support > Operating Systems > Linux / Variants > port I/O in c/c++
port I/O in c/c++
Posted by Kevin Cifuentes on July 6th, 2003


Hey all i need some of your help. I tried compiling this using Dev-C++ and
at no suprise it gave me an error. I say w/out suprise because I just
discovered that the _outp and possibly the _inp functions are
windows-specific in conio.h. I checked in conio.h provided in Dev-C++ and I
couldn't find the functions anywhere. Do any of you know where I can find a
header or library that has port I/O specific functions much similar to _inp
and _outp? Thanx. Here's the code:

Code:

#include <time.h>
#include <conio.h>

int status;
if(!m_iNote) return;
m_iNote = (unsigned)(1193280L / m_iNote);
_outp(0x43,0xb6);
_outp(0x42,(char)m_iNote);
_outp(0x42,(char)(m_iNote >> 8));
status = _inp(0x61);
_outp(0x61,status | 0x03);
delay( (clock_t)m_iDuration );
_outp(0x61, status );


Posted by Tauno Voipio on July 6th, 2003



"Kevin Cifuentes" <kc915hakrez@yahoo.com> wrote in message
news:YYLNa.6698$351.2754243@twister.nyc.rr.com...
In Linux, it's not too good an idea to mess with the timer chip ...

There is a way: the ioperm() function. Given root privileges, you can grant
the caller access to defined I/O ports below 0x400 with it.

As it's not healthy to run an application with valid root privileges, the
correct way is to make the executable setuid root and activate the root
privileges for the duration of the ioperm() call only.

The correct way to produce sounds is to use the sound system drivers.

HTH

Tauno Voipio
tauno voipio @ iki fi