Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timing for Graphics
#1
Ok, so I'm running into a problem. For the game I'm working on (it is my first real graphical game) I want to skip my graphics routines entirely unless it has been at least 1/60th of a second since the last time they ran (I hope that made sense) so that the other portions of my program can run faster. The problem I have is that the TIMER function of qbasic isn't precise enough, and when I try to use the CLOCK& function outlined in the FAQ, I get an overflow error. I'm wondering if anyone has any ideas for how I should go about correcting this; btw I've included a copy of the function. Also, if anyone feels like explaining the code, in regards to what ports are being accessed and what information is being peek'd I'm all ears. Thanks.

Code:
FUNCTION CLOCK&

  ' Get the number of timer ticks at
  ' 0000:046C
  DEF SEG = 0
  Ticks& = PEEK(&H46C)
  Ticks& = Ticks& + PEEK(&H46D) * 256
  Ticks& = Ticks& + PEEK(&H46E) * 65536
  DEF SEG

  ' Latch the counter and obtain the PIT
  ' countdown status.
  OUT &H43, &H4
  LSB = INP(&H40)
  HSB = 255 - INP(&H40)

  ' Compute the CLOCK& value
  CLOCK& = Ticks& * 256 + HSB

END FUNCTION
Reply
#2
Sorry about the clock& function, me being its official endorser, but you need to put a "&" directly after the "65536". In the afternoon, the number becomes too large for an integer or single precision, and qb's babysitting math evaluation wont know to use long integers unless you put that & there, like this:

Code:
Ticks& = Ticks& + PEEK(&H46E) * 65536&
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)