delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/10/10/19:45:50

Date: Mon, 10 Oct 1994 15:49:49 -0400 (EDT)
From: Kimberley Burchett <OKRA AT max DOT tiac DOT net>
Subject: keyboard messups
To: DJGPP Mailing List <djgpp AT sun DOT soe DOT clarkson DOT edu>

  Okay, y'all, I've gotten about 10 replies but few of them have really 
looked at my question.

  One person told me that I should do cumulative rotations on the 
original object.  I know this - this was a test to see how accurate the 
rotation was in fixed point.  And if it knocks off 35% of my radius after 
only one rotation, that is not accurate enough.
  Another person has told me that my do...while loop won't work.  Except
it does.
  Another has told me that fixed point is useless since floating point 
goes faster.  Well, I don't have a coprocessor.
  Another person said the problem might be in FixRotate().  This is a good
idea since it does affect variables passed by address.  But I have checked
this - down to the assembler source.  It isn't the problem.

  The point of my post was to point out an apparent bug with the keyboard
handlers.  One version of code worked, the other didn't, and the ONLY
difference between them is whether they waited for a keypress or not. 

  Here is the essence of the problem:

  do {
    /* do something */
  } while(kbhit() == 0);     /* repeat until a key is pressed */

  versus

  do {
    /* do something */
    while(kbhit()==0);       /* wait until a key is pressed */
  } while(getch() != 'q');   /* if they pressed 'q', quit */

  In the first example, things mess up.  The second example is fine.  Can 
anyone explain why?
  I remember now another time when I have run into problems using the 
keyboard functions in while loops.  I had a routine that would flip video 
pages and then wait for a vertical retrace.  It looked like this:

  do {
    FlipPages();
    WaitRetrace();
  } while(kbhit()==0);

  it didn't work until I changed it to this:

  while (kbhit()==0) {
    FlipPages();
    WaitRetrace();
  }

							Kim

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019