/* ioaddr.c A simple utility for io-input/output */ #ifndef __IOADDR_C #define __IOADDR_C #include "elastro.h" /*default the joystickport is 0x200, set it, if it is another address*/ static unsigned short joystickport = 0x200; static unsigned short joystickport2 = 0x200; void setJoystickPort( unsigned short portaddr) { joystickport = portaddr; } void setJoystickPort2( unsigned short portaddr) { joystickport2 = portaddr; } /*default the parallelport is 0x378 set it, if it is another address*/ static unsigned short parallelport = 0x378; static unsigned short parallelport2 = 0x378; void setParallelPort( unsigned short portaddr) { parallelport = portaddr; } void setParallelPort2( unsigned short portaddr) { parallelport2 = portaddr; } static inline unsigned char read_port( unsigned short port ) { unsigned char value; __asm__ volatile ("inb %1,%0" : "=a" (value) : "d" ((unsigned short)port)); return value; } static inline void write_port( unsigned char value, unsigned short port ) { __asm__ volatile ("outb %0,%1" : : "a" ((unsigned char)value), "d" ((unsigned short)port)); } /*call this if your program starts - you must only call once a time the permissions returns 1 if all ok, otherwise 0. In this case you have to end your program, or start is as root. */ int testPermissions( void ) { if ( iopl(3) != 0 ){ fprintf(stdout,"\r\nNo Permissions for special ports, start program as root, or with sudo\r\n"); return(0); } return(1); } /* do this in every case, before you end your program*/ void endPermissions( void ) { iopl(0); } #endif