#ifndef __base_c_ #define __base_c_ #include "base.h" 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)); } unsigned short joystickport = 0x200; unsigned short parallelport = 0x378; int pportmode = PPORTMODE_EPPECR; int initBase( unsigned short parport, unsigned short jport, int ppmode ) { if ( iopl(3) != 0 ){ fprintf(stdout,"\nNo Permissions for special ports, start program as root, or with sudo\n"); return(0); } if( parport ){ parallelport = parport; } if( jport ){ joystickport = jport; } if( ppmode ){ pportmode = ppmode; } switch( pportmode ){ case PPORTMODE_EPP: write_port( 4 , parallelport + 2 ); write_port( 0xff, parallelport ); break; case PPORTMODE_EPPECR: write_port( 4 , parallelport + 2 ); write_port( 0xff, parallelport ); write_port( 128, parallelport + 0x402 ); break; default: fprintf(stdout,"\nInvalid, or not supported parallelportmode\n"); iopl(0); return(0); } return(1); } void deinitBase( void ) { write_port( 4 , parallelport + 2 ); write_port( 0xff, parallelport ); iopl(0); } /* The generally elpara-base-board-functions. ############################################ */ unsigned char base_readinput( void ){ base_setdevice( BASE_BUFIO ); return( base_readdevice ); } void base_writeoutput( unsigned char value ){ base_setdevice( BASE_BUFIO ); base_writedevice(value); } void base_writelatch1( unsigned char value ){ base_setdevice( BASE_LATCH1 ); base_writedevice(value); } void base_writelatch2( unsigned char value ){ base_setdevice( BASE_LATCH2 ); base_writedevice(value); } void base_writelatch3( unsigned char value ){ base_setdevice( BASE_LATCH3 ); base_writedevice(value); } void base_writelatch4( unsigned char value ){ base_setdevice( BASE_LATCH4 ); base_writedevice(value); } void base_writelatchaddr16( unsigned short addr ){ unsigned short lval; lval = addr >> 8; lval = lval & 0x00ff; base_setdevice( BASE_LATCH2 ); base_writedevice((unsigned char)lval); lval = addr & 0x00ff; base_setdevice( BASE_LATCH1 ); base_writedevice((unsigned char)lval); } void base_writelatchaddr24( unsigned long addr ){ unsigned long lval; lval = addr >> 16; lval = lval & 0x000000ff; base_setdevice( BASE_LATCH3 ); base_writedevice((unsigned char)lval); lval = addr >> 8; lval = lval & 0x000000ff; base_setdevice( BASE_LATCH2 ); base_writedevice((unsigned char)lval); lval = addr & 0x000000ff; base_setdevice( BASE_LATCH1 ); base_writedevice((unsigned char)lval); } void base_writelatchaddr32( unsigned long addr ){ unsigned long lval; lval = addr >> 24; lval = lval & 0x000000ff; base_setdevice( BASE_LATCH4 ); base_writedevice((unsigned char)lval); lval = addr >> 16; lval = lval & 0x000000ff; base_setdevice( BASE_LATCH3 ); base_writedevice((unsigned char)lval); lval = addr >> 8; lval = lval & 0x000000ff; base_setdevice( BASE_LATCH2 ); base_writedevice((unsigned char)lval); lval = addr & 0x000000ff; base_setdevice( BASE_LATCH1 ); base_writedevice((unsigned char)lval); } /* ###### some specials with the little expansion ## */ unsigned char base_read_cs0( unsigned char off ){ base_setdevice( BASE_CS0 + (off & 0x0f)); return( base_readdevice ); } void base_write_cs0( unsigned char value, unsigned char off ){ base_setdevice( BASE_CS0 + (off & 0x0f)); base_writedevice(value); } /* ############# MISC ######################### */ /* some specials ------------- */ unsigned char read_jkeypad( void ) { unsigned char val,cval; cval = KEYPAD_NOKEY; val = read_port(joystickport) >> 4 & 0x0f; if(val == KEYPAD_NOKEY ){ return(val); } while(val == KEYPAD_HIGHALONE ){ val = read_port(joystickport) >> 4 & 0x0f; } cval = val; while( val != KEYPAD_NOKEY ) { val = read_port(joystickport) >> 4 & 0x0f; } return( cval ); } #endif //__base_c_