/*********************************************************************/ /* Copyright 1989 by H. Edward Hall */ /* */ /* Permission is hereby granted to copy and to give away this */ /* software as long as this notice is preserved in its entirety. */ /* You may modify the software or use it for any purpose just as */ /* long as you preserve this notice and do not sell the software. */ /* No warranty of any kind is made for this software. The holder */ /* of this copyright reserves the right to enhance and/or sell */ /* this software with no obligation to provide updates or further */ /* free copies; if this should happen you may still use this version */ /* of the software under the terms you received it with. */ /*********************************************************************/ #ifdef TURBOC #include #endif TURBOC #include "mpu401.h" #define NBUFFERED 1024 /* * Tickle the MPU's registers. */ /* * The following should be about 3000 for an AT, 1000 for a PC; */ #define DELAYFACT 3000 static unsigned char databuf[NBUFFERED]; static int nbuffered = 0; int putcmd(cmd) unsigned char cmd; { register int x; x = 0; while ((inportb(STATUS_PORT)&DRR) != 0) if (x++ > DELAYFACT) return -1; disable(); outportb(STATUS_PORT, cmd); for (;;) { x = 0; while ((inportb(STATUS_PORT)&RDY) != 0) if (x++ > DELAYFACT) { enable(); return -1; } x = inportb(DATA_PORT)&0xff; if (x != ACK) databuf[nbuffered++] = (unsigned char)x; else break; } enable(); return ACK; } int getdata() { register int x; if (nbuffered > 0) return (int)databuf[--nbuffered]; x = 0; while ((inportb(STATUS_PORT)&RDY) != 0) if (x++ > DELAYFACT) return -1; return (inportb(DATA_PORT)&0xff); } int putdata(val) unsigned char val; { register int x; x = 0; while ((inportb(STATUS_PORT)&DRR) != 0) if (x++ > DELAYFACT) return -1; outportb(DATA_PORT, val); return (int)val; }