From: "A.Appleyard" To: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU Date: Tue, 10 Jan 1995 15:30:13 GMT Subject: Cat and mouse games I am developing a Gnu C++ program which used many special keystrokes:- typedef unsigned char byte; int nextch; /*-----*/ byte get__key(){_ax=0x700; int21(); return _ax&255;} /* Return key typed, or 0 if the next call returns a special key */ /*-----*/ int get_key(){return get__key()?:-get__key();} /* Return key typed (special keys as negative, e.g. alt-Q as -16) */ /*-----*/ int getkey(){int i; if(nextch) {i=nextch; nextch=0; return i;} i=get_key(); return i;} /* Ditto, and use `nextch' as a 1-character input buffer to hold any character that was read and wasn't needed until later */ /*-----*/ <<>> I now want to bring the mouse in, putting the `read the mouse' routines in `int getkey' in such a way that pressing the left / middle / right buttons is returned by `int getkey' as if the three mouse buttons were extra keyboard keys returning the characters special-253 / special-254 / special-255. So as a part-way stage in developing it I tried this:- /*----- is a key waiting to be read? *//* This works OK */ int typahead() {if(nextch) return 1; _ax=0xb00; int21(); return _ax&255;} /*-----*/ /* wait n microseconds. This seems to work OK */ void wait(int n){_ax=0x8600; _cx=n>>16; _dx=n&0xffff; int15();} /*-----*/ int getkey(){int i; if(nextch) {i=nextch; nextch=0; return i;} Jerry.status(); /* read current mouse state */ A: Jerry.status(); if(!typahead()) goto A; i=get_key(); return i;} /*-----*/ This should merely keep track of mouse movements while waiting for me to type a key. (It doesn't yet exit the loop if I press a mouse button, I haven't got that far.) But when I ran it I found that it made the keyboard's hearing unreliable, i.e. sometimes it ignored and sometimes read the same key. I thought: "This is making PC call the `read mouse state' interrupt and the `is there a keystroke waiting?' interrupt alternately every microsecond or so, and so there isn't time for the (keyboard interrupt that happens when I press a key) to find enough spare time to happen.". So I tried inserting `wait(1);' or `for(i=0;i<1000;i++) XYZ++;' after the label `A:', to leave a microsecond gap in each loop so the keyboard interrupt has time to happen, but the PC still kept sometimes ignoring keyboard keys in this program. What is happening?