/* base.h The basic-io for the elpara base.brd Note: This functions currently only works with the EPP-mode of the parallelport. Perhaps later we implement also the normally 8bit-mode, and/or the standart printer-port, setting the necessary signals by our own, but currently we do not enjoy that. */ #ifndef __base_h_ #define __base_h_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*this is set by initBase, default 0x200*/ extern unsigned short joystickport; /*this is set by initBase, default 0x378*/ extern unsigned short parallelport; /*this is set by initBase, default PPORTMODE_EPPECR*/ extern int pportmode; #define PPORTMODE_SPP 1 #define PPORTMODE_PS2 2 #define PPORTMODE_EPP 3 #define PPORTMODE_EPPECR 4 /* NOTE: Currently only the modes PPORTMODE_EPP, and PPORTMODE_EPPECR supported ( till up to 2 Mb per Second possible ). Perhaps later we will support also the other modes, but then handshakesignals have to be generated extraordinary. ( Only till up to 100 kH possible ). PPORTMODE_EPPECR is nearly the same as PPORTMODE_EPP, but will write the EPP-Mode to the special ECR Register before. This is one of the shitty stuff cooked by Microsoft for ISA-base 1284 adapters with ECP. So if you see a EPP+ECP in your bios, normally this mode is necessary. (ECP is not supported by this). If it takes some trouble try PPORTMODE_EPP. */ /* call this if your program starts - you must only call once a time, before doing any other things with the ports. returns 1 if all ok, otherwise 0. In this case mostly you have no permissions for the ports, and to end your program. Try it as root, or with sudo again. parport should be one of the valid parallelportaddresses. Use 0 for that if you will use the defaultsetting 0x378. jport should be one of the valid joystickportaddresses. Use 0 for that if you will use the defaultsettting 0x200. mode should be set to one of the parallelport-modes above, but have a look, that currently only EPP, and EPPECR is supported. Use 0 for that if you will use the defaultsetting EPPECR. Function sets permissions for ports, and inits the parallelport. */ extern int initBase( unsigned short parport, unsigned short jport, int ppmode ); /* do this in every case, before you end your program, and a previous initBase was successfully. ( Do not call it if a previous initBase was unsuccessfully */ extern void deinitBase( void ); /* The generally elpara-base-board functions. ############################################# */ /* sets the address for the onboard 74HCT138 addr can be one of the following definitions. if the on-board 138 is not used, instead of using an external decoder, set bit 7 to low, in form ADDR & 127. A7 Low = 000-127 free for externals using PD0-PD7 o.a. 128-143 CS0 onboard free for externals using PD0-PD7 o.a. 144-159 CS1 onboard free for externals using PD0-PD7 o.a. 160-175 CS2 onboard free for externals using PD0-PD7 o.a. 176-191 CS3 onboard used for Latch 374 1 (OA0-OA7) 192-207 CS4 onboard used for Latch 374 2 (OB0-OB7) 208-223 CS5 onboard used for Latch 374 3 (OC0-OC7) 224-239 CS6 onboard used for Latch 374 4 (OD0-OD7) 240-255 CS7 onboard used for buffered io 245 (D0 - D7) These address are set by the upper bits A7-A4 of addr. The lower bits of addr A3-A0 are free for specials, add. devices ... You can set this by adding the range from 0-15 like: ADDR + ??. This function will not activate the device, instead only setting the latch addressed by ADDRSTROBE to the address which later then will activate the 138 with DATASTROBE. If you need own extension-devices with a own 138 you have to address it with a A7 = low, - to switch the onboard 138 off. (or using the definitions for that ). With the extension an additional extension for a longer busy signal is available, also a IORD, and IOWR, and a CS0IORD, CS0IOWR. ( CS0IORD, and CS0IOWR are ored with the CS0 signal 128-143 ) */ //first the stuff for own extensions #define BASE_EXCS0 0 #define BASE_EXCS1 16 #define BASE_EXCS2 32 #define BASE_EXCS3 48 #define BASE_EXCS4 64 #define BASE_EXCS5 80 #define BASE_EXCS6 96 #define BASE_EXCS7 112 #define BASE_CS0 128 #define BASE_CS1 144 #define BASE_CS2 160 //then the definitions for the onboard-devices #define BASE_CS3 176 #define BASE_CS4 192 #define BASE_CS5 208 #define BASE_CS6 224 #define BASE_CS7 240 #define BASE_LATCH1 BASE_CS3 #define BASE_LATCH2 BASE_CS4 #define BASE_LATCH3 BASE_CS5 #define BASE_LATCH4 BASE_CS6 #define BASE_BUFIO BASE_CS7 /*NOTE: The read_port, and write_port functions are static functions, for using it in own implementations, you have to include base.c, instead handling it as objectcode (Often this make sense, escpecially when polling input, or setting outputs to different values, not setting the device-address every time before) */ #define base_setdevice(x) write_port( x , parallelport + 3 ) #define base_writedevice(x) write_port( x , parallelport + 4 ) /*only useable for the BASE_BUFIO*/ #define base_readdevice read_port( parallelport + 4 ) /*sets the device BASE_BUFIO ( 74HCT245 ) and reads the value, and returns it*/ extern unsigned char base_readinput( void ); /*sets the device BASE_BUFIO ( 74HCT245) and writes the value to it*/ extern void base_writeoutput( unsigned char value ); /*sets the device BASE_LATCH1 ( 74HCT374) and writes the value to it*/ extern void base_writelatch1( unsigned char value ); /*sets the device BASE_LATCH2 ( 74HCT374) and writes the value to it*/ extern void base_writelatch2( unsigned char value ); /*sets the device BASE_LATCH3 ( 74HCT374) and writes the value to it*/ extern void base_writelatch3( unsigned char value ); /*sets the device BASE_LATCH4 ( 74HCT374) and writes the value to it*/ extern void base_writelatch4( unsigned char value ); /* these uses latch1, and latch2 as a 16 bit addressoutput latch1 becomes the lower 8 bits of addr, and latch2 the upper */ extern void base_writelatchaddr16( unsigned short addr ); /* these uses latch1, latch2, and latch3 as a 24 bit addressoutput latch1 becomes the lowest 8 bits of addr, and latch3 the highest */ extern void base_writelatchaddr24( unsigned long addr ); /* these uses all 4 latches as a 32 bit addressoutput latch1 becomes the lowest 8 bits of addr, and latch4 the highest (latch 4 as first, then latch 3, then ..... ) */ extern void base_writelatchaddr32( unsigned long addr ); /* sets address BASE_CS0, and reads input (with the expansion CS0 affects also the signal CS0RD.) off is a value from 0 to 15 affecting the addresssignals A0 to A3, which is added to the BASE_CS0 address. */ extern unsigned char base_read_cs0( unsigned char off ); /* sets address BASE_CS0, and writes to it. (with the expansion CS0 affects also the signal CS0WR.) off is a value from 0 to 15 affecting the addresssignals A0 to A3, which is added to the BASE_CS0 address. */ extern void base_write_cs0( unsigned char value, unsigned char off ); /* With the expansion the IOWR/IORD - Signals are available whenever a read, or write operation together with DATASTROBE ( reading/writing from/to parallelport + 4) is done, but only the BASE_CS0 signal is ored together with IOWR/IORD, so we have two additional signals CS0WR/CS0RD. All other addresses you can also use like these functions, making own combinations with the other addresses. example for CS0: base_setdevice( BASE_CS0 + (off & 0x0f)); return( base_readdevice ); base_setdevice( BASE_CS0 + (off & 0x0f)); base_writedevice(value); */ /* ############# MISC ######################### */ /*reads only the 4 inputlines of joystickport, and returnes it as the lower 4 bits.*/ #define read_jinput read_port(joystickport) >> 4 & 0x0f /* A simple utility for reading a build keypad from joystickport This is only for special stuff, connecting an elastro-keypad directly to the joystickport. This requires base.c */ #define KEYPAD_NOKEY 15 #define KEYPAD_LEFT 5 #define KEYPAD_RIGHT 3 #define KEYPAD_DOWN 9 #define KEYPAD_UP 7 #define KEYPAD_HIGHLEFT 4 #define KEYPAD_HIGHRIGHT 2 #define KEYPAD_HIGHDOWN 8 #define KEYPAD_HIGHUP 6 #define KEYPAD_FOLLOW 13 #define KEYPAD_STOP 11 #define KEYPAD_HIGHALONE 14 #define KEYPAD_HIGHFOLLOW 12 #define KEYPAD_HIGHSTOP 10 #define KEYPAD_HIGHFOLLOWRIGHT 0 #define KEYPAD_HIGHFOLLOWSTOPUP 0 #define KEYPAD_HIGHSTOPLEFT 0 extern unsigned char read_jkeypad( void ); #endif //__base_h_