October 19, 2021, 08:29:27 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
   Home   Help Search Login Register  
Pages: [1]
Author Topic: Timing for Graphics  (Read 2028 times)
Posts: 35

« on: August 09, 2003, 01:06:38 AM »

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.



  ' 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

  ' 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

Posts: 2567

« Reply #1 on: August 09, 2003, 01:08:50 AM »

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:

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
Pages: [1]
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!