TDE educational programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.6 KiB

/* libcqcam - shared Color Quickcam routines
* Copyright (C) 1996-1998 by Patrick Reynolds
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* Library General Public License for more details.
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
// I/O ports wrapper definitions and prototypes
// This file might need tweaking if you're trying to port my code to other
// x86 Unix platforms. Code is already available for Linux, FreeBSD, and
// QNX; see the Makefile.
// QNX code by: Anders Arpteg <>
// FreeBSD code by: Patrick Reynolds <> and Charles
// Henrich <>
// Inlining implemented by: Philip Blundell <>
#ifndef PORT_H
#define PORT_H
#include "config.h"
#include <unistd.h>
#ifdef __linux__
#if defined(HAVE_IOPERM)
#include <sys/io.h>
#endif /* HAVE_IOPERM */
#elif defined(QNX)
#include <conio.h>
#elif defined(__FreeBSD__)
#include <machine/cpufunc.h>
#include <stdio.h>
#elif defined(BSDI)
#include <machine/inline.h>
#elif defined(OPENBSD)
#include <machine/pio.h>
#elif defined(LYNX)
#include "lynx-io.h"
#elif defined(SOLARIS)
#include "solaris-io.h"
#error Please define a platform in the Makefile
#if defined(__linux__) && !defined(HAVE_IOPERM)
static char ports_temp;
#ifdef inb
#undef inb
#endif /* inb */
#define inb(port) \
lseek(devport, port, SEEK_SET), \
read(devport, &ports_temp, 1), \
#ifdef outb
#undef outb
#endif /* inb */
#define outb(data, port) \
lseek(devport, port, SEEK_SET); \
ports_temp = data; \
write(devport, &ports_temp, 1);
class port_t {
port_t(int iport);
inline int read_data(void) { return inb(port); }
inline int read_status(void) { return inb(port1); }
inline int read_control(void) { return inb(port2); }
#if defined(LINUX) || defined(LYNX)
inline void write_data(int data) { outb(data, port); }
inline void write_control(int data) { outb(control_reg = data, port2); }
inline void setbit_control(int data) { outb(control_reg |= data, port2); }
inline void clearbit_control(int data) { outb(control_reg &= ~data, port2); }
#else // Solaris, QNX, and *BSD use (port, data) instead
inline void write_data(int data) { outb(port, data); }
inline void write_control(int data) { outb(port2, control_reg = data); }
inline void setbit_control(int data) { outb(port2, control_reg |= data); }
inline void clearbit_control(int data) { outb(port2, control_reg &= ~data); }
inline int get_port() { return port; }
inline operator bool () const { return port != -1; }
int port; // number of the base port
int port1; // port+1, precalculated for speed
int port2; // port+2, precalculated for speed
int control_reg; // current contents of the control register
#ifdef LOCKING
int lock_fd;
int lock(int portnum);
void unlock(int portnum);
#ifdef FREEBSD
FILE *devio;
#if defined(__linux__) && !defined(HAVE_IOPERM)
int devport;